java - Item in getView() method returns always the last one -


i created json parse simple adapter shows result. works fine need retrieve url convert in bitmap. it's listview, url isn't 1 one,two,three or more. each url need create bitmap can show image each element of list.. actually, before getview() method part can display in log urls correctly. enter in getview() url can show last 1 parse json. onpostexecute() part use this:

@override           protected void onpostexecute(jsonobject json) {               pdialog.dismiss();           try {              // getting json array url               rating = json.getjsonarray(tag_item);               for(int = 0; < rating.length(); i++)              {                  jsonobject c = rating.getjsonobject(i);                  // storing  json item in variable                  string name = c.getstring(tag_nome);                  string commento = c.getstring(tag_commento);                  string valore = c.getstring(tag_valore);                  urlimage = c.getstring(tag_urlimage);                  string timestamp = c.getstring(tag_timestamp);                  log.i("url immagine", urlimage);// here shows 2 url , it's ok                   // adding value hashmap key => value                  hashmap<string, string> map = new hashmap<string, string>();                  map.put(tag_nome, name);                  map.put(tag_commento, commento);                  map.put(tag_valore, "voted: "+valore);                  map.put(tag_timestamp, timestamp);                  oslist.add(map);                   listadapter adapter = new simpleadapter(ratingdetailsactivty.this, oslist, r.layout.list_rating_item,                      new string[]                               { tag_nome,                                tag_commento,                                tag_valore,                                tag_urlimage,                                tag_timestamp                               }, new int[]                                        {                                         r.id.nome,                                         r.id.commento,                                          r.id.valore,                                          r.id.timestamp                                     })                   {                         @override                         public view getview(int position, view convertview, viewgroup parent) {                             view v = super.getview(position, convertview, parent);                              imageview profileimage = (imageview) v.findviewbyid(r.id.profile_img);                             try {                                 url url = new url(urlimage);                                 imageprofilo = bitmapfactory.decodestream(url.openconnection().getinputstream());                                 log.i("url immagine", urlimage); // here there last 1                              } catch (ioexception e) {                                 // todo auto-generated catch block                                 e.printstacktrace();                             }                             if (imageprofilo != null) {                                 profileimage.setimagebitmap(imageprofilo);                             } else {                                 profileimage.setimagedrawable(v.getresources() .getdrawable(r.drawable.welcome));                             }                             return v;                         }                   };                  list.setadapter(adapter);             }          } catch (jsonexception e) {            e.printstacktrace();          }         } 

so in way imageview set 1 image each item of list (using 1 url). i'm inside loop..why doesn't take urls?

try : in onpostexecute create list of maps

@override protected void onpostexecute(jsonobject json) {      try {         // getting json array url         rating = json.getjsonarray(tag_item);          for(int = 0; < rating.length(); i++)         {             jsonobject c = rating.getjsonobject(i);             // storing  json item in variable             string name = c.getstring(tag_nome);             string commento = c.getstring(tag_commento);             string valore = c.getstring(tag_valore);             string imageurl = c.getstring(tag_urlimage);             string timestamp = c.getstring(tag_timestamp);             log.i("url immagine", imageurl);// here shows 2 url , it's ok              // adding value hashmap key => value             hashmap<string, string> map = new hashmap<string, string>();             map.put(tag_nome, name);             map.put(tag_commento, commento);             map.put(tag_imageurl, imageurl);             map.put(tag_valore, "voted: "+valore);             map.put(tag_timestamp, timestamp);             oslist.add(map);              listadapter adapter = new simpleadapter(ratingdetailsactivty.this, oslist, r.layout.list_rating_item,                     new string[]                             { tag_nome,                                     tag_commento,                                     tag_valore,                                     tag_imageurl,                                     tag_timestamp                             }, new int[]                     {                             r.id.nome,                             r.id.commento,                             r.id.valore,                             r.id.timestamp                     });         }         list.setadapter(adapter);     } catch (jsonexception e) {         e.printstacktrace();     } } 

in getview, retreive list item using getitem(position), retreive url it

@override public view getview(int position, view convertview, viewgroup parent) { view v = super.getview(position, convertview, parent);  imageview profileimage = (imageview) v.findviewbyid(r.id.profile_img); try {     hashmap<string, string> map = (hashmap<string, string>)getitem(position);     url url = new url(map.get(tag_imageurl));     imageprofilo = bitmapfactory.decodestream(url.openconnection().getinputstream());     log.i("url immagine", urlimage); // here there last 1  } catch (ioexception e) {     // todo auto-generated catch block     e.printstacktrace(); } if (imageprofilo != null) {     profileimage.setimagebitmap(imageprofilo); } else {     profileimage.setimagedrawable(v.getresources() .getdrawable(r.drawable.welcome)); } return v; 

}


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -