i have a problem here in using spinner, i want to add value to each array item in my string.xml
this is my code:
<string-array name="hubungan">
<item>Choice</item>
<item>CHILD</item>
<item>PARENT</item>
<item>HUSBAND</item>
<item>WIFE</item>
</string-array>
I mean is:
<string-array name="hubungan">
<item>Choice value="1"</item>
<item>CHILD value="2"</item>
<item>PARENT value="3"</item>
<item>HUSBAND value="4"</item>
<item>WIFE value="5"</item>
</string-array>
2
Answers
try this
Well if you insist doing in this way try this example. The example will be as minimal as possible since you don’t provide enough code.
Your string array values as you defined but I modified the way of storing by convenince.
I will assume that you have a spinner and a textview in your activity / fragment. You can set this data and process it as needed like following:
Spinner definition in xml
This code must be located in your
onCreate
method if you use an activity, oronViewCreated
method if you use a fragment.There you go! Hope this helps you with your unique problem.