是否可能我可以使用选项和值创建微调器。
<select name=test>
<option value="1">Baran</option>
<option value="2">Khan</option>
</select>
使用微调器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>
我如何实现这样的目标。因为我需要将ID传递给服务器。
答案 0 :(得分:4)
您必须管理两个列表,并且两者都是动态的。
步骤实现:
Create
两个ArrayList<String>
。依赖于您的数据类型,我将其作为字符串数组。 Add value
到ArrayList。Create custom adapter
并传递两个列表适配器并根据该值获取值。 Add list
到Spinner Adapter。获取索引或位置
旋转器。 same index to get value from second list value
。Send that value to server
。See Demo Example that will Guide you to make easy.
享受!!!
答案 1 :(得分:1)
不是最好的,但一种方法是使用id创建另一个字符串数组:
<?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>
现在,当从数组i
中选择项test
时,您可以从数组i
中的项testIDS
获取ID。