4

有没有可能我可以创建一个带有选项和值的微调器。

<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 传递给服务器。

4

2 回答 2

4

您必须管理两个列表,并且两者都是动态的。

实现步骤:

  • Create两个ArrayList<String>。取决于您的数据类型,我在这里制作为字符串数组。
  • Add value到数组列表。
  • Create custom adapter并在其中传递两个列表适配器并据此获取值。
  • Add list到微调器适配器。获取 Spinner 的索引或位置。
  • 跟随same index to get value from second list value
  • Send that value to server.
  • 任务结束

请参阅演示示例,该示例将指导您轻松实现。

享受 !!!

于 2013-01-30T13:12:59.740 回答
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获取 id 。itestIDS

于 2013-01-30T12:29:58.297 回答