使用 Volley,我发出一个 StringRequest,并得到响应,如何使用 <select> Tag (DropDown) 键值?



使用Volley,我做了一个StringRequest并获取String对象作为响应。

@Override
public void onResponse(String response) {
Document doc = Jsoup.parse(response);  // response is HTML
Element e = doc.getElementById("contact_type");
String  option = e.text(); // output is :  Select Self CA ERI TRP Others
String  html = e.html();  // <select tag > given below
String option_value = e.val(); // not working
}

输出 [ 字符串 html = e.html(); ]

<select id="contact_type" style="width: 150px"  onblur="validateField_userContactDetails_SecContactType(this,true)" name="userContactDetails.SecContactType">
<option value="-1"> Select </option>
<option value="1">Self</option>
<option value="2">CA</option>
<option value="3">ERI</option>
<option value="4">TRP</option>
<option value="5">Others</option>
</select>

上面我使用文档来解析 HTML 响应。

由于 Volley 返回解析和结构化数据。那么如何获取下拉菜单键值对数据,这是响应。

是使用凌空功能将标签数据直接提取到哈希地图中的任何方法。

因为我想用上面的键值对数据填充我的微调器 UI。

首先只做两个数组引用,(如 String[] contact_type_key,contact_type_value)

try {
Elements e = doc.select("select[id=contact_type] > option");
// initializing the array
contact_type_key = new String[e.size()];
contact_type_value = new String[e.size()];
// getting data into array
for (Element data : e) {
contact_type_key[e.indexOf(data)] = data.ownText();
contact_type_value[e.indexOf(data)] = data.attr("value");
}
} catch (Exception ex) {
}

比将键数组与微调器一起使用并获取值数组[索引] onItemSelected...

最新更新