Reputation: 694
I'm new in Android. I have story.xml
in string folder which contains:
<string-array name="story">
<item>
<name>st2</name>
<id>1</id>
</item>
<item>
<name>st1</name>
<id>2</id>
</item>
</string-array>
I use this code to get this array and show in ListView
:
String[] sto_li = getResources().getStringArray(R.array.story);
ArrayAdapter<String> storylist;
storylist = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, sto_li);
list.setAdapter(storylist);
In list view show like this:
st21
.............
st12
But I only want to show:
st2
.........
st1
What is the best way to get the second output on ListView
?
Upvotes: 1
Views: 107
Reputation: 91
Get the identifier for the name like so: int resId = getResources().getIdentifier("story", "name", getPackageName());
Then do:
String[] sto_li = getResources().getStringarray(resId);
Give that a try.
Upvotes: 1