Sadik Sadik - 2 months ago 17
Android Question

How to get items from string array in java?


<string-array name="shopping">
<item>Istinye Park</item>
<item>Kanyon Istanbul</item>
<item>Forum Istanbul</item>
<item>Istanbul Cevahir</item>
<item>Istanbul Sapphire</item>

I have here code. And I need to access to specific item of string-array from java. For ex: to string: it is like- R.string.something, it is easy. And I can access to array too, like, But after it to some item I can't, I tried like,[1] or something like that but it didn't work. Please can you help me, I need to know how to access to some specific item with single line code.

Answer Source

You can load it via the resources with getStringArray, then just manipulate it like a standard array.

Resources res = getResources(); //assuming in an activity for example, otherwise you can provide a context.
String[] shoppingItems = res.getStringArray(;
String istanbul = shoppingItems[1]; //Kanyon Istanbul