android - How to use listview and checkbox? -
i have adaptor class getview
method follows:
public view getview(int position, view convertview, viewgroup parent) { view view = null; if (convertview == null) { layoutinflater inflator = context.getlayoutinflater(); view = inflator.inflate(r.layout.userlist, null); final viewholder viewholder = new viewholder(); viewholder.text2 = (textview) view.findviewbyid(r.id.stuname); viewholder.text = (textview) view.findviewbyid(r.id.rollno); viewholder.checkbox = (checkbox) view.findviewbyid(r.id.cb); viewholder.checkbox .setoncheckedchangelistener(new compoundbutton.oncheckedchangelistener() { @override public void oncheckedchanged(compoundbutton buttonview, boolean ischecked) { model element = (model) viewholder.checkbox .gettag(); element.setselected(buttonview.ischecked()); // toast.maketext(getcontext(), "checked", // toast.length_short).show(); } }); 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.text.settext(list.get(position).getname()); holder.text2.settext(list.get(position).getroll()); holder.checkbox.setchecked(list.get(position).isselected()); return view; }
there oncheckedchange
listener here.
my question how pass information list item has changed main activity? how in main activity can perform action when checkbox state has changed?
one idea call checkbox.settag()
, tagging data want hold , having oncheckedchange
listener use checkbox.gettag()
retrieve data. onclick
via xml.
Comments
Post a Comment