this question has answer here:
- lazy load of images in listview 37 answers
i using json parser parse json response, able item names in listview not able images corresponding it. image url's present in json response. how can parse response images corresponding items.
my code..
jsonparser.java
public class jsonparser { static inputstream = null; static jsonobject jobj = null; static string json = ""; // constructor public jsonparser() { } public jsonobject getjsonfromurl(string url) { // making http request try { // defaulthttpclient defaulthttpclient httpclient = new defaulthttpclient(); httppost httppost = new httppost(url); httpresponse httpresponse = httpclient.execute(httppost); httpentity httpentity = httpresponse.getentity(); = httpentity.getcontent(); } catch (unsupportedencodingexception e) { e.printstacktrace(); } catch (clientprotocolexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } try { bufferedreader reader = new bufferedreader(new inputstreamreader( is, "iso-8859-1"), 8); stringbuilder sb = new stringbuilder(); string line = null; while ((line = reader.readline()) != null) { sb.append(line + "\n"); } is.close(); json = sb.tostring(); } catch (exception e) { log.e("buffer error", "error converting result " + e.tostring()); } // try parse string json object try { jobj = new jsonobject(json); } catch (jsonexception e) { log.e("json parser", "error parsing data " + e.tostring()); } // return json string return jobj; } }
then in main class ..............................
jsonparser jparser1 = new jsonparser(); json1 = jparser1.getjsonfromurl(url0); try { log.d("parsing json data", "before json1 try2"); activities = json1.getjsonarray(tag_activities); log.d("parsing json data", "after activiti"); (int = 0; < activities.length(); i++) { jsonobject c = activities.getjsonobject(i); log.d("parsing json data", "inside loop"); string time = c.getstring("time"); user_name = c.getstring("user_name"); // image_url=c.getstring("thumb"); // bitmapfactory.options bmoptions; // bmoptions = new bitmapfactory.options(); // bmoptions.insamplesize = 1; // bitmap bm = loadimage(image_url, bmoptions); string utype = c.getstring("type"); hashmap<string, object> temp11 = new hashmap<string, object>(); log.d("parsing json data", "inside if"); if (utype.contains("user")) { temp11.put(tag_user_name, user_name + " " + join); } else if (utype.contains("checkin")) { subscriber_name = c.getstring("subscriber_name"); temp11.put(tag_user_name, user_name + " " + checkin1 + " " + subscriber_name); } else { subscriber_name = c.getstring("subscriber_name"); temp11.put(tag_user_name, user_name + " " + favorite1 + " " + subscriber_name); // temp11.put("subscriber_name", subscriber_name); } temp11.put(tag_time, time); temp11.put("image1", bm); list13.add(temp11); } } catch (jsonexception e) { e.printstacktrace(); } }
use image uploader , pass image url in demo
1) nostra's universal image loader.
2) fedor's lazylist. and;
3) novoda's imageloader.
Comments
Post a Comment