【发布时间】:2020-07-18 03:36:48
【问题描述】:
我通过 GET 得到 json 请求
{"data": [
"Черногория",
"Чехия",
"Чили"
]}
如果您需要在单独的项目中显示每个国家/地区,如何解析它。我正在使用 Pojo。
@SerializedName("data")
@Expose
private ArrayList<String> data = null;
这是一个我使用改造连接的活动,一切都来了,但只显示列表中的最后一个字段
public void onResponse(Call<Countries> call, Response<Countries> response) {
if (response.code() == 200) {
Countries countries = response.body();
if (countries != null) {
for (int x =0; x<countries.getData().size(); x++) {
arrayList.add(countries);
viewAdapterCountry.notifyDataSetChanged();
}}}
}
这个适配器
private ArrayList<Countries> countryModels;
Countries countryModel = countryModels.get(i);
List<String> country = countryModel.getData();
for (int x = 0; x<country.size(); x++){
viewHolder.button.setText(country.get(x));
}
【问题讨论】:
-
你不是总是用
viewHolder.button.setText(country.get(x));覆盖按钮文本,所以列表中的最后一个条目就是你看到的那个吗? -
这样做,viewHolder.button.setText(country.toString());显示所有内容,但不是在每个按钮中,而是全部在一个中
标签: java android json parsing retrofit