You can declare an integer array with a record for each row. I did this for an array of colors once, so I think it works for strings too.
RES / value / arrays.xml
<integer-array name="app_strings"> <item>@string/app_label</item> <item>@string/what_label</item> <item>@string/where_label</item> <item>@string/when_label</item> <item>@string/timezone_label</item> <item>@string/attendees_label</item> <item>@string/today</item> <item>@string/tomorrow</item> </integer-array>
Then in your code you will iterate over the array and use each value as an argument to getString ().
int[] stringIds = getResources().getIntArray(R.array.app_strings); String[] strings = new String[stringIds.length]; for (int i = 0; i < stringIds.length; i++) { strings[i] = getString(stringIds[i]); }
The problem is that you need to manually update the arrays.xml file whenever you change your string resources, so it is definitely not perfect.
Karakuri
source share