Hi,
I have a ListView showing names of Countries. I have stored the names in strings.xml as a string-array called country_names.
In populating the ListView, I use an ArrayAdapter which reads from strings.xml
String[] countryNames = getResources().getStringArray(R.array.country_names);
ArrayAdapter<String> countryAdapter = new ArrayAdapter<String>(this, R.layout.checked_list, countryNames);
myList.setAdapter(countryAdapter);
Now I also have a CountryCode for each country. When a particular country name is clicked on the List, I need to Toast the correspoding CountryCode.
I understand implementing a HashMap is the best technique for this. As far as I know, the hashMap is populated using put() function.
myMap.put("Country",28);
Now my questions:
1 ) Is it possible to read the string.xml array and use it to populate the Map? I mean, I want to add items to the Map, but I must be able to do so by reading the items from another array. How to do this?
The basic reason for my asking is because I want to keep the Country names and codes in a place where it is easier to add/remove/modify.
2 ) The string-arrays are stored in strings.xml. Where must similar integer arrays be stored? In values folder, but under any specific xml file?
Regards, kiki