Home » Android » arrays – How to get tag name instead of value of a spinner in android-Exceptionshub

arrays – How to get tag name instead of value of a spinner in android-Exceptionshub

Posted by: admin February 26, 2020 Leave a comment

Questions:

I want to program an application which user can select different behaviors from a spinner list. the spinner entries is from an string-array.My app is multi language and user will see the list based on his/her system language. The problem is when user select an item,getItem just return the value of selection item ,but the thing that i actually need is tag name of user selection.

In Strings.xml, I have:

    <string-array name="apps_categories">
        <item>@string/apps_applications</item>
        <item>@string/apps_games</item>
    </string-array>

as an example, in strings.xml, I have the following strings that are available in different languages.

    <string name="apps_applications">Application</string>
    <string name="apps_games">Games</string>

values-de –>strings.xml

    <string name="apps_applications">Bewegung</string>
    <string name="apps_games">Spile</string>

For example, when user select Application, my code return apps_applications.
here I tried different way but didn’t work

spSettingsLaunchBehavior.getAdapter().getItem(vPosition)

int vPosition = spSettingsLaunchBehavior.getSelectedItemPosition();
String value = getView().getContext().getResources().getStringArray(R.array.apps_categories)[vPosition];
How to&Answers: