android - Listview with checkedtextview repeating the checked items -


i have implemented listview custom arrayadapter, each row consists of checkedtextview widget. when check first item of listview , scroll down, find other items of listview gets checked, , more scroll down , find elements checked. looks first child check how replicates other listview child not visible.

i know have option of using choicemode, not working custom arrayadapter, , have use custom arrayadapter. object type string arrayadapter, have found online examples of custom models maintain checkbox tag, using string, can't to.

i pasting code of adapter:

@override     public view getview(final int position, view convertview, viewgroup parent) {         // todo auto-generated method stub          final viewholderclass viewholder;          if(convertview==null)         {             layoutinflater layoutinflater = (layoutinflater) context.getsystemservice(context.layout_inflater_service);             convertview = layoutinflater.inflate(r.layout.disruption_routes_list_child, parent, false);              viewholder = new viewholderclass();             initui(convertview, viewholder);              convertview.settag(viewholder);         }         else         {             viewholder = (viewholderclass) convertview.gettag();         }           viewholder.ctvroutes.settext(alroutes.get(position));            viewholder.ctvroutes.setonclicklistener(new onclicklistener() {              @override             public void onclick(view arg0) {                 // todo auto-generated method stub                 if(viewholder.ctvroutes.ischecked())                 {                     viewholder.ctvroutes.setchecked(false);                 }                 else                 {                     viewholder.ctvroutes.setchecked(true);                 }             }         });            return convertview;     }           private void initui(view convertview, viewholderclass viewholder) {         // todo auto-generated method stub         viewholder.ctvroutes = (checkedtextview) convertview.findviewbyid(r.id.ctvroutes);     }        static class viewholderclass     {         checkedtextview ctvroutes;       } 

this duo fact android list recycled

to on come either have custom object populate list in provide field called example ischecked , inside getview()

you following

if(yourlist.get(position).ischecked())     viewholder.ctvroutes.setchecked(true); else     viewholder.ctvroutes.setchecked(false); 

or provide arraylist of int

in store checked positions , inside getview()

check if position exist inside array make checked else unchecked

i kinda first approach since want search array inside main thread specially if arraylist huge make scroll lag


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -