【发布时间】:2017-10-04 23:37:24
【问题描述】:
我的 ArrayList 有 100 行,但我只想显示前 10 个条目。也许有人会知道怎么做?
try {
JSONObject jsonObj = new JSONObject(jsonStr);
JSONArray devices = jsonObj.getJSONArray("list");
for (int i = 0; i < devices.length(); i++) {
JSONObject c = devices.getJSONObject(i);
String id = c.getString("id");
String name = c.getString("name");
String known = c.getString("known");
String description = c.getString("description");
String controllerId = c.getString("controllerId");
JSONObject frequencySurvey = c.getJSONObject("frequencySurvey");
if (frequencySurvey.has("5000")) {
JSONObject fivezero = frequencySurvey.getJSONObject("5000");
String timestamp = fivezero.getString("timestamp");
String clients = fivezero.getString("clients");
String enabled = fivezero.getString("enabled");
HashMap<String, String> device = new HashMap<>();
device.put("id", id);
device.put("name", name);
device.put("enabled", enabled);
device.put("clients", clients);
DevicesList.add(device);
}
}
}
ListAdapter adapter = new SimpleAdapter(Devices_5_0.this, DevicesList,
R.layout.list_item, new String[]{ "name","clients","enabled"},
new int[]{R.id.name,R.id.clients, enabled});
lv.setAdapter(adapter);
创建时:
DevicesList = new ArrayList<>();
全局声明:
ArrayList<HashMap<String, String>> DevicesList;
我绝对不能提前限制我的清单
【问题讨论】:
标签: android sorting arraylist hashmap