Android Spinner parameter value is the same as Select Tag

Is it possible that I can create a counter with parameters and values.

<select name=test>
<option value="1">Baran</option>
<option value="2">Khan</option>
</select>

      

using spinner XML:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="test">
    <item Value="1">Baran</item>
    <item value="2">Khan</item>
</string-array>
</resources>

      

How can I achieve such a goal. As I need to pass the IDs to the server.

+3


source to share


2 answers


You need to manage two lists and both are as dynamic as you want.

Step to achieve:

  • Create

    two ArrayList<String>

    . Depends on your data type, which I am creating as a String Array.
  • Add value

    to ArrayList.
  • Create custom adapter

    and pass two list adapters into it and get the value accordingly.
  • Add list

    for adapter Spinner. Get the index or position of the Spinner.
  • Follow same index to get value from second list value

    .
  • Send that value to server

    ...
  • The task


See a demo to help you simplify.

Enjoy !!!

+4


source


Not the best, but one way would be to create another array of strings with IDs:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="test">
    <item Value="1">Baran</item>
    <item value="2">Khan</item>
</string-array>
<string-array name="testIDS">
    <item>1</item>
    <item>2</item>
</string-array>
</resources>

      



Now that an item is i

selected from an array test

, you can get an ID from an item i

in the array testIDS

.

+1


source







All Articles