0

I use below code in my array.xml file inorder to defining a array:

<string-array name="cities_azarbayejanSharghi">
    <item id="15">A</item>
    <item id="36">B</item>
    <item id="140">C</item>
    <item id="95">D</item>
</string-array>

I want to access the id of each field in the code when it is selected as spinner's selecteditem. Is there any ways?

Husein Behboudi Rad
  • 5,434
  • 11
  • 57
  • 115

2 Answers2

0
TypedArray ta = getResources().obtainTypedArray(R.array.your_array);
int resId = ta.getResourceId(arg_positionItem, 0);
deadfish
  • 11,996
  • 12
  • 87
  • 136
0

You could be better off referencing other strings, such as the answer outlined here:

<string name="15">A</string>
<string name="36">B</string>

<string-array name="cities_azarbayejanSharghi">
    <item>@string/15</item>
    <item>@string/36</item>
</string-array>
Community
  • 1
  • 1
Daniel Wilson
  • 18,838
  • 12
  • 85
  • 135