【发布时间】:2018-10-11 12:50:59
【问题描述】:
我有两个微调器,第二个微调器的值取决于第一个微调器。 spinner 中的每个项目都有一个来自 JSON 的 id。现在,我想获取第二个微调器的项目 ID。我得到所选项目的名称,但我需要所选项目的名称和 ID。
call.enqueue(new Callback<Map<String, ResponseJSON2>>()
{
@Override
public void onResponse
(Call<Map<String, ResponseJSON2>> call, retrofit2.Response<Map<String, ResponseJSON2>> response) {
responseJson = response.body();
if (responseJson != null) {
for (Map.Entry<String, ResponseJSON2> e : responseJson.entrySet()) {
provincesList.add(e.getKey());
for (Model c : e.getValue().getModel()) {
citiesList.add(c.getName());
}
}
}
createAdapter();
}
}
谢谢。
模型.java
public class Model {
private String id;
private String name;
private String taxonomy;
private String description;
private String images;
private String parent;
//getter and setters
@Override
public String toString() {
return "model{" +
"id='" + id + '\'' +
", name='" + name + '\'' +
", taxonomy='" + taxonomy + '\'' +
", description='" + description + '\'' +
", images='" + images + '\'' +
", parent='" + parent + '\'' +
'}';
}
}
【问题讨论】:
-
城市列表是字符串类型的?
-
@UmangBurman no , private ArrayList
cityList = new ArrayList(); -
您还需要存储 ids 的 int 数组列表。
-
我觉得一定是hashmap @UmangBurman
-
是的,为 ids 创建一个 hashmap。然后你就可以得到id