gpt4 book ai didi

android - 在 Bundle 中插入 ArrayList

转载 作者:行者123 更新时间:2023-11-29 17:56:09 24 4
gpt4 key购买 nike

我有一个以下类型的 ArrayList:

ArrayList<HashMap<String, String>> data

我试图将此数据 传递给Bundle 我没有找到任何方法来实现它。我最接近的是:

putParcelableArrayList

有人可以帮忙吗?

最佳答案

ArrayList 是可序列化的(以及 HashMap 和字符串),所以试试 putExtra(String, Serializable) Intent 中传递值和 getSerializableExtra(String) 检索数据的方法。

传递 ArrayList<HashMap<String, String>>从Activity A到Activity B

Intent intent = new Intent(this, B.class);
HashMap<String, String> hm = new HashMap<String, String>();
hm.put("key", "value");
ArrayList<HashMap<String, String>> arl = new ArrayList<HashMap<String, String>>();
arl.add(hm);
intent.putExtra("data", arl);
startActivity(intent);

在下一个 Activity 中检索如下数据

ArrayList<HashMap<String, String>> arl = (ArrayList<HashMap<String, String>>) getIntent().getSerializableExtra("data");
System.out.println("serialized data.."+arl);

关于android - 在 Bundle 中插入 ArrayList,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19174129/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com