简体   繁体   中英

How to load JSON data into Android Listview?

I want to load JSON data into the List view with subtitle and images (Left side on the row).

Here below I have posted my sample JSON response code :

 for (int i = 0; i < contacts.length(); i++) {
    JSONObject obj = contacts.getJSONObject(i);
    Iterator keys = obj.keys();
    while(keys.hasNext()) {

      // loop to get the dynamic key
       String currentDynamicKey = (String)keys.next();

       // store key in an arraylist which is A,B,...
       // get the value of the dynamic key
       JSONArray currentDynamicValue = obj.getJSONArray(currentDynamicKey);
       Log.d("Response: ", "> " + currentDynamicKey);



      int jsonrraySize = currentDynamicValue.length();
         if(jsonrraySize > 0) {
             for (int ii = 0; ii < jsonrraySize; ii++) {
                  JSONObject nameObj = currentDynamicValue.getJSONObject(ii);
                  String name = nameObj.getString("name");
                  System.out.print("Name = " + name);
                  //Log.d("Response: ", "> " + name);

                  //store name in an arraylist
             }                    
         }
      }
}

I want to Show Tittle : currentDynamicKey values and Sub Title : Name string values.

If you already have your data and you don't necessarily need to integrate the server requests with your adapter, then you really just need an adapter which supports a JSONArray. There's a really nice open source one within the Advanced-Adapters library. Then it's just a matter of passing the JSONArray to the adapter and setting the adapter to a ListView .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM