0

I have an array defined in my strings.xml file "names". I want the values in a local array in my program. how can i do this?

<string-array name="Names">

<item>  Adi </item>
<item>  John </item>
<item>  Adelaide    </item>
<item>  Alicante    </item>
</string-array name>

I want these values to be stored in a local array named item[]. Please help!

2 Answers 2

2

Slightly modified from the docs:

Resources res = getResources();
String[] item = res.getStringArray(R.array.Names);
Sign up to request clarification or add additional context in comments.

1 Comment

thanks a lot dude.. it worked! It says u can accept an answer in 8 mins.. will do that in 8! :P
1
<resources>
    <string-array name="planets_array">
        <item>Mercury</item>
        <item>Venus</item>
        <item>Earth</item>
        <item>Mars</item>
    </string-array>
</resources>

Resources res = getResources();
String[] planets = res.getStringArray(R.array.planets_array);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.