android - Getting Adapter information of BaseAdapter Before Deletion -


i have custombase adapter button attached it,when click on button row deleted, working fine, problem is, data populated in adapter remote server, want getting information contained adapter before deleting , giving mainactivity, in case, getting title before view removed , sending server, telling delete storage, big issue code button in baseadapter class, not know if can give mainactivity data before row deleted, cannot think of way of achieving that, if has idea please share, below base adapter.

public class cartadapter extends baseadapter{   private arraylist<listitem> listdata; private layoutinflater layoutinflater; viewholder holder; public cartadapter(context context, arraylist<listitem> listdata) {     this.listdata = listdata;     notifydatasetchanged();     layoutinflater = layoutinflater.from(context); } @override public void notifydatasetchanged() {     super.notifydatasetchanged(); }  @override public int getcount() {     return listdata.size(); }  @override public object getitem(int position) {     return listdata.get(position); }  @override public long getitemid(int position) {     return position; }  public view getview(final int position, view convertview, viewgroup parent) {           if (convertview == null) {         convertview = layoutinflater.inflate(r.layout.singlecartitem, null);         holder = new viewholder();         holder.title = (textview) convertview.findviewbyid(r.id.title);         final imagebutton delete = (imagebutton) convertview.findviewbyid(r.id.delete);         convertview.findviewbyid(r.id.postcommentbox);          delete.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view v) {                  listdata.remove(position);                 notifydatasetchanged();               }         });         convertview.settag(holder);         delete.settag(holder);      } else {         holder = (viewholder) convertview.gettag();     }      final listitem newsitem = listdata.get(position);     holder.title.settext(newsitem.gettitle());        return convertview; }   static class viewholder {     textview title;    int position;   } 

}

are using listfragment? if do, check this out.

if not, make activity implement interface e.g. handledeletion method e.g. handletitle(string title). in clicklistener cast context object handledeletion , call method handletitle(string title) on it. called callback.

[edit] example:

public interface handledeletion {     handletitle(string title); }  public class myactivity implements handledeletion {     ...     handletitle(string title) {         //do whatever want      }     ... }   public class cartadapter extends baseadapter{     ...      private context context;      public cartadapter(context context, arraylist<listitem> listdata) {         this.listdata = listdata;         this.context = context;         notifydatasetchanged();         layoutinflater = layoutinflater.from(context);     }      public view getview(final int position, view convertview, viewgroup parent) {     ...      delete.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view v) {                 ((handledeletion)context).handletitle(listdata.get(position).gettitle());                 listdata.remove(position);                 notifydatasetchanged();               }         });     ...     }     ... } 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -