java - How to check a checkbox if it is checked prevoiusly -
i have implemented check box in list, there names check box. problem is, select 5 names , display names, after if come list, again 5 names should checked because have selected names.
but unchecked when have revisited. how achieve this.
my adapter code.
holder.userid_fk.settext(tempvalues.getuserid_fk().tostring()); holder.chkbox.setoncheckedchangelistener(null); holder.chkbox.setchecked(checkedholder[position]); log.i(tag, "position " + checkedholder[position]); if (checkedholder[position]) holder.chkbox.setchecked(true); else holder.chkbox.setchecked(false); holder.chkbox.setoncheckedchangelistener(new compoundbutton.oncheckedchangelistener() { @override public void oncheckedchanged(compoundbutton buttonview, boolean ischecked) { checkedholder[position] = ischecked; log.i(tag, "position " + checkedholder[position]); } });
my activity code..
list.setonitemclicklistener(new onitemclicklistener() { public void onitemclick(adapterview<?> parent, view view, int position, long id) { checkbox cb = (checkbox) view.findviewbyid(r.id.chkbox); cb.performclick(); if (cb.ischecked()) { (int = 0; < adapter.getcount(); i++) { if (adapter.checkedholder[i]) { // name values checked user membername.clear(); membername.add(itemsarr.get(i).getitemname().tostring()); cb.setchecked(true); log.i(tag, "name " + membername); // name = itemsarr.get(i).getitemname().tostring(); //log.i(tag, "name " + name); } } } else if (!cb.ischecked()) { } } });
unless store state somewhere, every time go list treated new instance. result boxes go being unchecked.
when go away list, save checked values sort of persistent storage, device storage, or pass state of boxes screen you're going can passed list when navigating back. alternatively save them variable has global scope , won't fall out of scope when moving screens.
when go list, see if there's state used (either in device storage, passed in parameter, or whatever means of persistence use) use re-check appropriate boxes.
Comments
Post a Comment