Reputation: 54013
In my Android app I want to make a list of options that can be clicked. On whichever item you click, it always brings you to the same next screen but with a different .putextra(). I can do this with a simple ListAdapter as is done here.
That works fine, but I do want the values to be translated in the app for different languages. I guess this means I need to define all the values in the listview in my strings.xml. I can of course define some values in strings.xml, but I wouldn't know where to start to get values from my strings.xml into a listview.
Does anybody know how I would be able to get translatable values into an Android ListView? Any tips are welcome!
Upvotes: 1
Views: 1749
Reputation: 5971
You have two options:
strings.xml
and make a list or array contains
their ids. you can use what @TabrejKhan has said for this option.Like:
<string-array name="my_string_list">
<item>String 1</item>
<item>String 2</item>
<item>String 3</item>
<item>String 4</item>
<item>String 5</item>
</string-array>
And in your java code create the adapter
ArrayAdapter<CharSequence> dataAdapter = ArrayAdapter.createFromResource(activity,
R.array.my_string_list);
Upvotes: 5
Reputation: 894
A simple answer is.... Create your array like this:
String[] listItems = {R.string.text1, R.string.text2, R.string.text3, R.string.text4 /*and so on*/ };
Upvotes: 0