android - Get the Json Array data in listview -
i got problem json array
data, have tried following code using can json response
in listview
getting single data in response getting single item why?
here code:
url = "some url"; httpclient mhttpclient = new defaulthttpclient(); httpget mgetmethod = new httpget(url); httpresponse mreponsemessage = mhttpclient.execute(mgetmethod); string response = entityutils.tostring(mreponsemessage.getentity()); log.d("tag", "o/p response " + response); jsonarray responseobject = new jsonarray(response); system.out.println("responseobject="+responseobject); for(int i=0; i<responseobject.length(); i++) { obj = responseobject.getjsonobject(i); }
here json response
[{"dmessage":"sfsfs","message":"sfsf","mp3":"kalimba.mp3","user_message_id":"85","category":"lottery","title":"dgfs"},{"dmessage":"prueba","message":"prueba","mp3":"na","user_message_id":"80","category":"lottery","title":"prueba"},{"dmessage":"prueba","message":"prueba","mp3":"na","user_message_id":"79","category":"lottery","title":"prueba"},
here obj response object
,in response object getting single value
could me solve issue thanks!
in loop looping through values in array , storing in same variable replaces value each time , contains last value.
solution :
arraylist<hashmap<string, string, string, string, string, string>> mp3list = new arraylist<hashmap<string, string, string, string, string, string>>(); for(int i=0; i<responseobject.length(); i++) { jsonobject obj = responseobject.getjsonobject(i); string dmessage= obj.getstring("dmessage"); string message= obj.getstring("message"); string mp3= obj.getstring("mp3"); string usermessageid= obj.getstring("user_message_id"); string category= obj.getstring("category"); string title= obj.getstring("title"); //making use of obtained strings adding arraylist display in listview hashmap<string, string, string, string, string, string> map = new hashmap<string, string, string, string, string, string>(); // adding each child node hashmap key => value map.put("dmessage", dmessage); map.put("message", message); map.put("mp3", mp3); map.put("usermessageid", usermessageid); map.put("category", category); map.put("title", title); // adding hashlist arraylist mp3list.add(map); } //you have data in mp3list. display in listview listadapter adapter = new simpleadapter(this, mp3list, custom_listitem_layout_id, new string[] { "dmessage", "message", "mp3", "usermessageid", "category", "title"}, new int[] { dmessage_textview_id, message_textview_id, mp3_textview_id, usermessageid_textview_id, category_textview_id,title_textview_id }); listview.setadapter(adapter);
Comments
Post a Comment