如何在arraylist中设置文本

时间:2017-05-06 11:35:01

标签: android arraylist hashmap settext

我尝试了很多可能性而且都没有效果。它需要更改第三个值,以便在显示列表时立即更改值

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);

在第三个值中,我得到了值&#34; false&#34;或&#34;真&#34;我想设置false = Not active但是true = Active

的OnCreate

        tv = (TextView) findViewById(R.id.enabled);
        DevicesList = new ArrayList<>();

全球宣布:

 private ListView lv;
private TextView tv;
ArrayList<HashMap<String, String>> DevicesList;

1 个答案:

答案 0 :(得分:0)

在for循环

的条件下尝试这个
DevicesList.add(i,device);

而不是

DevicesList.add(device);