How to get a String array with java code from the list <string-item> in the arrays.xml file in Android?
I want to get an array of strings reading from the arrays.xml file that we add to android values. Can someone kindly give a solution for this. Otherwise, I will have to enter each of these entries in the strings.xml file and pass them into java code using getResources()getString()
Thanks. Tharindu
+6
Tharindu madushanka
source share4 answers
I don't have an IDE in front of me right now, but I think you should do something like R.res.arrays.YOUR_ARRAY_OF_STRINGS.
+2
broschb
source share getResources().getStringArray(R.array.umc_profile_values); 4 worked for me!
+9
Piyush patel
source share Resources res = getResources(); String[] name = res.getStringArray(R.array.name_array); +6
Anil mh
source share <resources> <string name="app_name">App name</string> ... <string-array name="scale"> <item>Excellent</item> <item>Good</item> <item>Fair</item> <item>Poor</item> </string-array> </resources> If you want to get 1 element in an array using java
String val1 = getResources().getStringArray(R.array.scale)[0]; Or you can get everything
String[] values = getResources().getStringArray(R.array.scale); +1
Vasil Valchev
source share