java - Images in gridview change their position while scrolling -


hi i'm having kind of problem, when scrolling imageviews change positions , background images. saw other answers on topic on site, non of them helped me.

like once: grid view scrolling issue gridview scrolling problem on android gridview elements changes place dynamically when scroll screen

and many others...but don't solve problem.

important thing don't use custom layout gridview or gridview items(imageviews).i create them programmatically. important me if know answer pls me...thanks.

public view getview(int position, view convertview, viewgroup parent) {     if(convertview==null){         imageview = new imageview(ctx);     } else {         imageview = (imageview) convertview;     }         imageview.setlayoutparams(new gridview.layoutparams(85, 85));         imageview.setscaletype(imageview.scaletype.center_crop);         imageview.setpadding(8, 8, 8, 8);         imageview.setbackgroundresource(tmp[position]);         imageview.setimageresource(blank);      return imageview; } 

its simple method. adapters recycle each , every view while scrolling. need create ones being re-used after first time. holders avoid expensive calls findviewbyid , re-use items getting old ones , changing properties.

one point need keep in mind need hold images displayed in 1 of containers array[] or list , reset each time before returning view, or else display last recycled view.

public view getview(int position, view convertview, viewgroup parent) {             // todo auto-generated method stub              layoutinflater inflater = (layoutinflater) activity                     .getsystemservice(context.layout_inflater_service);              if (convertview == null) {                 convertview = inflater.inflate(r.layout.item_layout, null);                 holder = new viewholder();                 holder.cover = (imageview) convertview                         .findviewbyid(r.id.item_cover);                 convertview.settag(holder);              } else {                 holder = (viewholder) convertview.gettag();              }          holder.cover.setbackgroundresource(tmp[position]);          return convertview ;     }      static class viewholder {         imageview cover;     } 

Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -