This is my array
String colors[] = {"Red","Blue","White","Yellow","Black", "Green","Purple","Orange","Grey"};
i want to put this array's values to <strings-array > </string-array>
in values/string.xml at runtime. is it possible ?? if possible then how ?
Asked
Active
Viewed 593 times
0

Bojan Kseneman
- 15,488
- 2
- 54
- 59

protiksani
- 1
- 3
1 Answers
2
Yes you can.
<?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>
And get them like this
Resources res = getResources();
String[] planets = res.getStringArray(R.array.planets_array);

Bojan Kseneman
- 15,488
- 2
- 54
- 59
-
i want to reverse structure of your answer – protiksani May 03 '15 at 12:42
-
1No. strings.xml cannot be changed in the Runtime. But you can use SharedPreferences to save your strings there. – Bojan Kseneman May 03 '15 at 12:44
-
See here http://stackoverflow.com/questions/10813841/storing-a-string-array-in-the-sharedpreferences – Bojan Kseneman May 03 '15 at 12:47