I'm new to Android. I did search around but couldn't find anything work like NSdictionary of iOS in Android. For example in iOS I can create SIMPLE array of dictionary like this format
Array
idx1: [objA1 for keyA],[objB1 for keyB],[objB1 for keyC]
idx2: [objA2 for keyA],[objB2 for keyB],[objB2 for keyC]
idx3: [objA3 for keyA],[objB3 for keyB],[objB3 for keyC]
I know I can create string-array that work similar like that in android
<string-array name="list_obj1">
<item>ObjA1</item>
<item>ObjB2</item>
<item>ObjC3</item>
</string-array>
<string-array name="list_obj2">
<item>ObjB1</item>
<item>ObjB2</item>
<item>ObjB3</item>
</string-array>
<string-array name="list_obj3">
<item>ObjC1</item>
<item>ObjC2</item>
<item>ObjC3</item>
</string-array>
My question is if there is anything else used to create AN array of dictionary in Android like iOS.
Thank you for your help.
First, I think there are many tutorial about this stuff then you can search for more info. Since you are new to android you might not know the "name" to search. For this case, "HashMap" is what you looking for. It works like NSdictionary.
//Create a HashMap
Map <String,String> map = new HashMap<String,String>();
//Put data into the HashMap
map.put("key1","Obj1");
map.put("key2","Obj2");
map.put("key3","Obj3");
// Now create an ArrayList of HashMaps
ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
//Add the HashMap to the ArrayList
mylist.add(map);
Now you have st like an array of dictionary.
Hope this help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With