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 ?

0

1 Answer 1

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);
Sign up to request clarification or add additional context in comments.

3 Comments

i want to reverse structure of your answer
No. strings.xml cannot be changed in the Runtime. But you can use SharedPreferences to save your strings there.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.