0

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 ?

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

1 Answers1

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