android - How can I update my Listview from a Delete button in my custom row? -


i have built custom row listview shows contents of users cart. i've added button can delete row want to. code start of adapter below.

public class cartdetailadapter extends arrayadapter<cartdetail> {     context context;     int layoutresourceid;     cartdetail data[] = null;      public cartdetailadapter(context context, int layoutresourceid, cartdetail[] data) {         super(context, layoutresourceid, data);         this.layoutresourceid = layoutresourceid;         this.context = context;         this.data = data;     } 

you can see data of type cartdetail class lists items in custom row. code i've set out removebttn set out in getview().

holder.removebttn = (button)row.findviewbyid(r.id.removebttn); holder.removebttn.settag(position);  holder.removebttn.setonclicklistener(new view.onclicklistener() {     public void onclick(view v) {         integer index = (integer) finalholder.removebttn.gettag();         data.remove(index.intvalue());         notifydatasetchanged();     } }); 

as data variable of type cartdetail[] , not arraylist, cannot use remove delete item list. how can remove item cartdetail[], need create own method?

you can't delete data array, suggest use arraylist instead, if insist can use method.

list<carddetail> list = new arraylist<carddetail>(arrays.aslist(data)); list.remove(position); data = list.toarray(); 

Comments