android how to click the button which is in the listview item to delete that item -
custom list adapter class.
@override public view getview(final int position, view convertview, viewgroup parent) { viewholder holder; if(convertview == null) { layoutinflater inflater = (layoutinflater) context .getsystemservice(context.layout_inflater_service); convertview = inflater.inflate(r.layout.cart_item, null); holder = new viewholder(); holder.image = (imageview) convertview.findviewbyid(r.id.item_image); holder.name = (textview) convertview.findviewbyid(r.id.item_name); holder.price = (textview) convertview.findviewbyid(r.id.item_price); holder.qty = (spinner) convertview.findviewbyid(r.id.spinner_qty); holder.delete_btn = (button) convertview.findviewbyid(r.id.delete_btn); convertview.settag(holder); }else{ holder = (viewholder) convertview.gettag(); } //holder.image holder.name.settext(productarray.get(position).getname()); holder.price.settext("$"+ productarray.get(position).getprice()); arrayadapter<string> adapter = new arrayadapter<string>(context, android.r.layout.simple_spinner_item, quantity); adapter.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item); holder.qty.setadapter(adapter); return convertview; }
how click delete_btn delete listview item. don't know how access listview. pls help!
add inside getview() :
holder.delete_btn.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { yourlist.remove(position); notifydatasetchanged(); } });
Comments
Post a Comment