Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

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);
share|improve this question
1  
Why can you not just take the item at the index in the array? .getResources().getStringArray(R.array.link_cetagories)[0] – daentech Jul 1 at 10:55
up vote 1 down vote accepted

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.

share|improve this answer

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]
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.