java - holder returning wrong view -


i uploading list server. showing through 'adapter'. loading image of every list element in background.

after loading every images calling notifydatasetchanged() adapter , accordingly getview() has been called refresh every image each list element.

problem have updated image last list element. understanding "holder = (viewholder) rowview.gettag();" returning holder view.

but if uncommenting 2 lines below:

//                holder.textview = (textview) rowview.findviewbyid(r.id.tvappname); //                holder.imageview = (imageview) rowview.findviewbyid(r.id.ivimage);  getting expected result; don't want call findviewbyld.       private static class viewholder {         public imageview imageview;         public textview textview;         public int rowcount = 0;     }         public view getview(int position, view convertview, viewgroup parent) {              view rowview = convertview;             if (rowview == null) {                 layoutinflater inflater = getlayoutinflater();                 rowview = inflater.inflate(r.layout.applist_item, null, true);                  holder.textview = (textview) rowview.findviewbyid(r.id.tvappname);                 holder.imageview = (imageview) rowview.findviewbyid(r.id.ivimage);                 rowview.settag(holder);             } else {                 holder = (viewholder) rowview.gettag(); //                holder.textview = (textview) rowview.findviewbyid(r.id.tvappname); //                holder.imageview = (imageview) rowview.findviewbyid(r.id.ivimage);             }              apkdata app = getitem(position);             holder.textview.settext(app.getappname());              drawable mpic = loadimage(app);             holder.imageview.setimagedrawable(mpic);              return rowview;         }      private drawable loadimage(final apkdata item) {             if (item.geticonimage() != null) {                 log.v(constants.tag, "item.geticonimage() != null");                 return item.geticonimage();             } else {                 log.v(constants.tag, "item.geticonimage() == null");             }              mexecutor.execute(new runnable() {                 @override                 public void run() {                      if (!(thread.currentthread().isinterrupted())) {                         drawable res = null;                         bitmap image = null;                         int trycount = 0;                         while ((image == null) && (trycount <= constants.try_connecction)) {                             image = utils.loadimage(item.geticonpath(),                                     holder.imageview.getlayoutparams().height,                                     holder.imageview.getlayoutparams().width);                             trycount++;                         }                         if (image != null) {                             res = new bitmapdrawable(getresources(), image);                         }                          if (res == null) {                             res = getresources().getdrawable(r.drawable.android_app_icon_logo);                         }                          item.seticonimage(res);                          asyncnotifydatachanged();                     }                 }             });             return getresources().getdrawable(r.drawable.android_app_icon_logo);         }      //utils.loadimage:     public static bitmap loadimage(string urlstr, int height, int width) {         if (!urlstr.startswith("http://") && !urlstr.startswith("https://"))             urlstr = "http://" + urlstr;         url url;         try {             url = new url(urlstr);             bitmap mimg = null;             mimg = bitmapfactory.decodestream(url.openconnection().getinputstream());             return scaleimage(mimg, height, width);         } catch (malformedurlexception e) {             log.e(constants.tag, "loadimage malformedurlexception:", e);             return null;         } catch (ioexception e1) {             log.e(constants.tag, "loadimage ioexception:", e1);             return null;         } catch (nullpointerexception ex) {             log.e(constants.tag, "loadimage nullpointerexception:", ex);             return null;        }     } 

you have create holder every view...

... rowview = inflater.inflate(r.layout.applist_item, null, true); viewholder holder = new viewholder(); holder.textview = (textview) rowview.findviewbyid(r.id.tvappname); .... 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -