android - When the GridView scrolls, it changes CheckBox Selections -


accualy read posts cant solution problem. , need help.

i have got gridview. filling grids baseadapter. grids has got imageviews , checkboxes. longtouching grid , checking checkbox. done here.

but when scroll gridview selections changing. try solution other posts can't fix problem.

adapter getview method;

@override public view getview(final int position, view convertview, viewgroup parent) {     // todo auto-generated method stub      view grid;     if (convertview == null) {         grid = new view(mcontext);         layoutinflater inflater = (layoutinflater) mcontext.getsystemservice(context.layout_inflater_service);         grid = inflater.inflate(r.layout.mygrid, parent, false);     } else      {         grid = (view) convertview;     }      imageview imageview = (imageview) grid.findviewbyid(r.id.imagepart);     final checkbox ch = (checkbox)grid.findviewbyid(r.id.checkbox);     ch.settag(position);      hashmap<string,string> tar;     tar = data.get(position);      imageloader.displayimage(tar.get(fragmentb.fotoyol),imageview);      grid.setonlongclicklistener(new view.onlongclicklistener() {         @override         public boolean onlongclick(view v) {             checkbox chh = (checkbox)v.findviewwithtag(position);             chh.setchecked(true);             return false;         }     });      return grid; } 

if delete (convertview == null) line , remove else block then, checks not changing when checkbox going unseen because of scroll, returning scroll checkbox , unchecked. not permanently checked.

i need big help. thank you...

you need keep checked status backing data, not (only) in view. means onlongclicklistener has add item tar map:

tar.put("checked", "true"); 

and getview(…) method (outside doubleclick listener) needs initialize checkbox data:

string checked = tar.get("checked"); grid.findviewwithtag(position).setchecked(         checked != null && boolean.getboolean(checked)     ); 

note: have declare tar final reachable inside listener.


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -