2016-07-16 2 views
1

は、私はありがとう リスト<HashMap>をバンドルに入れるには?私の断片で

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


} 

にバンドルにmovieListを保存することができる方法

List<HashMap> movieList

あります。あなたがこの方法を試すことができます

+1

[SerializableオブジェクトからArraylist of Hashmap]の可能な複製物(http://stackoverflow.com/questions/17233566/serializable-object-to-arraylist-of-hashmap) –

+1

あなたは構造全体を作ることを試みることを歓迎します'Serializable'。つまり、私はこれがセーブされたインスタンス状態 'Bundle'に入るべきものであると懐疑的です。 – CommonsWare

+0

@BertrandMartelありがとう – Rangtian

答えて

1

...

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()); 
} 

あなたが同じデータを取得します。ムービーモデルクラスがシリアライズ可能であることを確認してください。

+0

ありがとうPrashant。 ArrayListがSerializableであることがわかりました。 – Rangtian

関連する問題