0

I'm a beginner Android Developer. I would like to find out how I could access a string array out of string.xml and use it. I searched the internet inside out and found nothing. I found ways to put it into text-view right away, but that's not what I want to do. So, basically, I want to put the string array into another array. string.xml:

<?xml version="1.0" encoding="utf-8"?>

<resources>
<string-array name="Solar System">
    <item>Sun</item>
    <item>Mercury</item>
    <item>Venus</item>
    <item>Earth</item>
    <item>Mars</item>
    <item>Jupiter</item>
    <item>Saturn</item>
    <item>Uranus</item>
    <item>Neptune</item>

So I want this xml string array into a java string array

Thank's for the POSITIVE HELP, I'm sorry, I thought that way that was shown by many of you didn't work. It was just another error in my program.

-Thanks

3
  • 1
    Both answer is right please check and accept if helpful. Commented Nov 16, 2013 at 4:41
  • I searched the internet inside out and found nothing. Really? What did you search for? Unicorn food? Here's a tutorial. bit.ly/1d4sEcJ Commented Nov 16, 2013 at 8:51
  • unicorns.co.za/unicorn-facts/unicorn-food.html Commented Nov 17, 2013 at 0:14

2 Answers 2

1

Use the below

String[] planets = getResources().getStringArray(R.array.Planets);
Sign up to request clarification or add additional context in comments.

Comments

1

Seriously? The example where you got that from even shows how you to access it:

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

2 Comments

I didn't get it from that example, not even close
If you scroll down a bit to the example, it is exactly the same. All you did was change the name.

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.