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 ?
1 Answer
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);
3 Comments
protiksani
i want to reverse structure of your answer
Bojan Kseneman
No. strings.xml cannot be changed in the Runtime. But you can use SharedPreferences to save your strings there.
Bojan Kseneman