Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing an item from ListView inside a custom adapter

I have a custom listview item that includes a 'remove' button. I created a custom adapter called LazyListAdapter that extends BaseAdapter. Inside the getView method that I override I set this button's onclick method as follows:

@Override
public View getView(final int pos, View convertView, ViewGroup parent) {

     View v = convertView;

     // Some other things...

     ImageButton removeFav = (ImageButton) v.findViewById(R.id.removeFavorites);

     removeFav.setOnClickListener(new OnClickListener() {

     @Override
     public void onClick(View v) {

          // I delete the object from Parse database here,
          // Therefore I want the view to disappear here
     }
}

How can I delete or somehow hide the corresponding view by using a code inside this onclick method? Or should I change my approach?

Thank you so much in advance.

like image 475
ecem Avatar asked Apr 17 '13 15:04

ecem


1 Answers

Try this

@Override
public View getView(final int pos, View convertView, ViewGroup parent) {

    View v = convertView;

    // Some other things...

    ImageButton removeFav = (ImageButton) v.findViewById(R.id.removeFavorites);

    removeFav.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {

       // After you delete the object from Parse database here,
       notifyDataSetChanged();

    }
}
like image 111
Ankit Avatar answered Sep 19 '22 20:09

Ankit