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?

2 Answers 2

0
TypedArray ta = getResources().obtainTypedArray(R.array.your_array);
int resId = ta.getResourceId(arg_positionItem, 0);
Sign up to request clarification or add additional context in comments.

Comments

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.