One thing you could do to get strings from dynamic keys is to make 2 string arrays and put them in a HashMap.
arrays.xml:
<?xml version="1.0" encoding="utf-8"?> <resources> <string-array name="title_keys"> <item>title1</item> <item>title2</item> <item>title3</item> </string-array> <string-array name="title_values"> <item>Real Title 1</item> <item>Real Title 2</item> <item>Real Title 3</item> </string-array> </resources>
And in your code:
String[] titleKeys = getResources().getStringArray(R.array.title_keys); String[] titleValues = getResources().getStringArray(R.array.title_values); HashMap<String, String> titles = new HashMap<String, String>(); for(int i = 0; i < titleKeys.length; i++) { titles.put(titleKeys[i], titleValues[i]); }
Finally, to get captions from a dynamic key:
titles.get(titleFromSomewhere);
Krauxe
source share