Hi want to get the arraylist from the resources.xml is there any code for this.please give me some suggestions.Thanks in advance
Not entirely sure what you want, but this might be worth a read: http://developer.android.com/guide/topics/resources/string-resource.html
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="planets_array">
<item>Mercury</item>
<item>Venus</item>
<item>Earth</item>
<item>Mars</item>
</string-array>
</resources>
How to retrieve the array in your application with code:
Resources res = getResources();
String[] planets = res.getStringArray(R.array.planets_array);
Price_array in strings.xml is assigned to Arraylist
private ArrayList<String> price_unit;
price_unit= new ArrayList<String>(Arrays.asList(getResources().getStringArray(R.array.Price_array)));
I have done this way:
string.xml:
Define String Array:
<string-array name="my_string_array">
<item>Test 1</item>
<item>Test 2</item>
<item>Test 3</item>
<item>Test 4</item>
<item>Test 5</item>
<item>Test 6</item>
</string-array>
In Activity.class / Fragment.class:
List<String> myArrayList = Arrays.asList(getResources().getStringArray(R.array.my_string_array));
Done
A modification to Klaus' answer, to get an ArrayList<String>
:
ArrayList<String> myResArrayList = new ArrayList<String>();
Resources res = getResources();
Collections.addAll(myResArrayList, res.getStringArray(R.array.myResArray));
Use Arrays.asList :
String[] myResArray = getResources().getStringArray(R.array.my_array);
List<String> myResArrayList = Arrays.asList(myResArray);
This list will be immutable, so if you want a mutable list, just do :
List<String> myResMutableList = new ArrayList<String>(myResArrayList);