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,
As one of the possibilities, you may store 2 different arrays in XML: string array and integer array, and then programmatically put them in the HashMap
.
Definition of arrays:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="countries_names">
<item>USA</item>
<item>Russia</item>
</string-array>
<integer-array name="countries_codes">
<item>1</item>
<item>7</item>
</integer-array>
</resources>
And code:
String[] countriesNames = getResources().getStringArray(R.array.countries_names);
int[] countriesCodes = getResources().getIntArray(R.array.countries_codes);
HashMap<String, Integer> myMap = new HashMap<String, Integer>();
for (int i = 0; i < countriesNames.length; i++) {
myMap.put(countriesNames[i], countriesCodes[i]);
}
It may be a file with any name. See this