You could do this:
String[] CountryCaptital = context.getResources().getStringArray(R.array.countrycaptital);
Then access it as you would any java array. (note the misspelling of "country capital" in your naming...)
EDIT:
Sorry - I didn't realize you were trying to reference the attribute of an item
. That is not possible. From the docs:
<item>
A string, which can include styling tags. The value can be a
reference to another string resource. Must be a child of a
element. Beware that you must escape apostrophes and
quotation marks. See Formatting and Styling, below, for information
about to properly style and format your strings.
No attributes.
http://developer.android.com/guide/topics/resources/string-resource.html
You could create two separate string arrays of the same length and use one as the key to the other when creating a HashMap
, for example.
EDIT:
Two arrays like this:
<resources>
<string-array name="capital">
<item >New Delhi</item>
<item >Tokyo</item>
<item >Washington</item>
<resources>
and:
<resources>
<string-array name="country">
<item >India</item>
<item >Japan</item>
<item >US</item>
<resources>
String[] country = context.getResources().getStringArray(R.array.country);
String[] capital = context.getResources().getStringArray(R.array.capital);
Then create a HashMap
and use a for
loop to populate it.