How do I delete an item from my custom base adapter?

后端 未结 5 1679
半阙折子戏
半阙折子戏 2020-12-16 22:29

I am extending BaseAdapter to make a custom listview row. I have context menu that opens everytime a user holds on the row and prompts if he wants to delete it. However how

5条回答
  •  無奈伤痛
    2020-12-16 22:42

    You should add a Listener on your adapter to handle the delete event.

    public YourAdapter(Context context, List rows, View.OnClickListener deleteListener) 
    { ... }
    

    And on your getView() method set the listener

    yourBtn.setOnClickListener(this.deleteListener);
    

    You can add a value on the btn tag to identifiy the current row :

    yourBtn.setTag(position);
    

    Finally, on your Activity, your listener will fire with the current position in tag. You can then use the previous answer to update your adapter and refresh your listview.

提交回复
热议问题