android - How to delete a item from a custom Listview -
i want delete item listview
on selecting check box in listview
. custom adapter
follows:
public class listadapter extends arrayadapter<list> { private int resource; private layoutinflater inflater; private context context; // private final boolean[] mcheckedstate; private final arraylist<list> list; private final activity mcontext; boolean checkall_flag = false; boolean checkitem_flag = false; public listadapter(activity context, arraylist<list> list) { super(context, r.layout.listdata, list); this.mcontext = context; this.list = list; } static class viewholder { protected textview text1; protected textview text2; protected checkbox checkbox; } @override public view getview(int position, view convertview, viewgroup parent) { viewholder viewholder = null; if (convertview == null) { layoutinflater inflator = mcontext.getlayoutinflater(); convertview = inflator.inflate(r.layout.listdata, null); viewholder = new viewholder(); viewholder.text1 = (textview) convertview .findviewbyid(r.id.textviewlat); viewholder.text2 = (textview) convertview .findviewbyid(r.id.textviewlng); viewholder.checkbox = (checkbox) convertview .findviewbyid(r.id.checkboxlist); viewholder.checkbox .setoncheckedchangelistener(new compoundbutton.oncheckedchangelistener() { @override public void oncheckedchanged(compoundbutton buttonview, boolean ischecked) { int getposition = (integer) buttonview.gettag(); // here position have set checkbox using settag. list.get(getposition).setselected( buttonview.ischecked()); // set value of checkbox maintain state. } }); convertview.settag(viewholder); convertview.settag(r.id.textviewlat, viewholder.text1); convertview.settag(r.id.textviewlng, viewholder.text2); convertview.settag(r.id.checkboxlist, viewholder.checkbox); } else { viewholder = (viewholder) convertview.gettag(); } viewholder.checkbox.settag(position); // line important. viewholder.text1.settext(list.get(position).getlat()); viewholder.text2.settext(list.get(position).getlng()); viewholder.checkbox.setchecked(list.get(position).isselected()); return convertview; }
}
please guide changes need make delete item in listview
on selecting checkbox
.
Comments
Post a Comment