android - Check/Uncheck a checkbox inside a listview, programmatically? -


i have listview 2 textviews , checkbox. using custom adaptor fill listview.

i want check/uncheck checkbox of particular listitem of listview based on listitem's position. example: if want check checkbox of second item of listview, how can this?

you have in getview() method.

sample code vogella

@override   public view getview(int position, view convertview, viewgroup parent) {     view view = null;     if (convertview == null) {       layoutinflater inflator = context.getlayoutinflater();       view = inflator.inflate(r.layout.yourlayout, null);       final viewholder viewholder = new viewholder();       viewholder.checkbox = (checkbox) view.findviewbyid(r.id.check);       viewholder.checkbox           .setoncheckedchangelistener(new compoundbutton.oncheckedchangelistener() {              @override             public void oncheckedchanged(compoundbutton buttonview,                 boolean ischecked) {               model element = (model) viewholder.checkbox                   .gettag();               element.setselected(buttonview.ischecked());              }           });       view.settag(viewholder);       viewholder.checkbox.settag(list.get(position));     } else {       view = convertview;       ((viewholder) view.gettag()).checkbox.settag(list.get(position));     }     viewholder holder = (viewholder) view.gettag();     holder.checkbox.setchecked(list.get(position).isselected());     return view;   } }  

for more detail see here.

i hope you.


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -