我正在开发一个带有微调器的android应用程序。 微调项目和微调值是不同的。我想从包括微调框中收集所有的值,并设置一个休息api服务到web后端。这里是响应数组。在Android中使用自定义适配器为Spinner设置值
{"Status":true,"errorType":null,"countryList":[{"Code":"US","Name":"United States"},{"Code":"CA","Name":"Canada"},{"Code":"AU","Name":"Australia"},{"Code":"GB","Name":"United Kingdom"}]}
我成功绑定的名称的JSONObject来微调器,但我不能添加代码。
这是我的代码。
JSONObject responseObject = new JSONObject(res);
String status=responseObject.getString("Status");
JSONArray JA = responseObject.getJSONArray("countryList");
JSONObject json= null;
if(status.equals("true")) {
final String[] str2 = new String[JA.length()];
for (int i=0;i<JA.length();i++)
{
json = JA.getJSONObject(i);
str2[i] = json.getString("Name");
}
sp = (Spinner) findViewById(R.id.citnzshp_field);
list = new ArrayList<String>();
for(int i=0;i<str2.length;i++)
{
list.add(str2[i]);
}
Collections.sort(list);
ArrayAdapter<String> adp;
adp = new ArrayAdapter<String>
(getApplicationContext(),android.R.layout.simple_dropdown_item_1line, list);
sp.setAdapter(adp);
}
我如何可以将绑定在代码的JSONObject来微调器的表单提交后服用。
任何人都可以请分享我制作自定义适配器绑定数据到微调和选择价值也的优势。
退房:http://stackoverflow.com/questions/24712540/set-key-and-value-in-spinner/24712664#24712664 –