I try to search converting JSONObject
to HashMap
but most of the results are for Java not Android. Hence, I hope someone can share if you have experien
You could do something like this:
ListView listView = (ListView) findViewById(R.id.listView);
// ...
@Override
public void onResponse(JSONObject response) {
List> list = new ArrayList>();
try {
Iterator iterator = response.keys();
while (iterator.hasNext()) {
String key = iterator.next();
String value = response.getString(key);
HashMap map = new HashMap<>();
map.put(KEY_ID, key);
map.put(KEY_NAME, value);
list.add(map);
}
} catch (JSONException e) {
e.printStackTrace();
}
if(list.size() > 0) {
String[] from = {KEY_ID, KEY_NAME};
int[] to = {R.id.text_id, R.id.text_name};
SimpleAdapter adapter = new SimpleAdapter(MainActivity.this, list,
R.layout.list_item, from, to);
listView.setAdapter(adapter);
}
}