3

Is it possible to get string from string-array in xml file? I need to a string not string-array :)

strings.xml

<string-array name="link_categories">
    <item>http://google.com</item>
    <item>http://yahoo.com</item>
  </string-array>

Brabra.java

 WebPageCurrent = getResources().getString(get string from string array);
1
  • 3
    Why can you not just take the item at the index in the array? .getResources().getStringArray(R.array.link_cetagories)[0] Commented Jul 1, 2015 at 10:55

2 Answers 2

17

To get String from strings.xml you should have key for that String.But in the above you have key for String array so you have to get String array from that you have to get required String.

CurrentWebpage = getResources().getStringArray(R.array.link_categories)[0];

Hope this will helps you.

Sign up to request clarification or add additional context in comments.

Comments

1

You need to write below code :-

Context con=getApplicationContext();
String[] your_array = con.getResources().getStringArray(R.array.your_array_string);

Now you have string array and you can pick your string from your array .

WebPageCurrent = your_array[0];// may be [1],[2]

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.