get list of the strings present in strings.xml file in Android
You can declare your strings in res\values\strings.xml file like this.
<string-array name="vehiclescategory_array"> <item>Cars</item> <item>Bikes</item> <item>RVs</item> <item>Trucks</item> <item>Other Vehicles</item> </string-array>
In your activity class, you can access them like the following.
String[] categories;categories=getResources().getStringArray(R.array.vehiclescategory_array);
In the above list, whatever sequence you declare, the same way it is assigned to the array in your activity. Suppose Cars will be assigned to categories[0]. Hope this helps.
Field[] fields = R.string.class.getDeclaredFields(); // or Field[] fields = R.string.class.getFields();String str = "";for (int i =0; i < fields.length; i++) { int resId = getResources().getIdentifier(fields[i].getName(), "string", getPackageName()); str += fields[i].getName() + " = "; if (resId != 0) { str += getResources().getString(resId); } str += "\n";}
You will get all codes of strings with its values in "str" variable.
If you want to access all the Strings from the strings.xml
file you could use reflection on the R.string
class. An example can be found in this answer, you'll just need to replace drawables with strings.