如何将List<HashMap>放入Bundle?

How to put List<HashMap> into Bundle?

在我的片段中,有一个

List<HashMap> movieList

如何将 movieList 存储到

中的 Bundle 中
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);


}

谢谢。

你可以这样试试...

HashMap<String, String> contactsMap = new HashMap<>();
contactsMap.put("key1" , "value1");
contactsMap.put("key2" , "value2");

ArrayList<HashMap> list = new ArrayList<>();
list.add(contactsMap);

Bundle b = new Bundle();
b.putSerializable("HASHMAP", list);

ArrayList<HashMap> hashmapList = (ArrayList<HashMap>)            b.getSerializable("HASHMAP");
HashMap<String, String> map = hashmapList.get(0);

for (Map.Entry<String, String> entry : map.entrySet()) {
    System.out.println(entry.getKey()+" : "+entry.getValue());
}

您将获得相同的数据。确保您的电影模型 class 是可序列化的。