ListView not “refreshing” after item is deleted from it

后端 未结 6 1644
半阙折子戏
半阙折子戏 2021-01-28 16:27

I am trying to figure out how I \"Refresh\" the list view the user is on when an item from my listview is deleted. I have tried notifyDataSetChanged() but to no avail, which is

6条回答
  •  不思量自难忘°
    2021-01-28 17:05

    Thanks for all the help guys, but in the end the answer I came up with is quite different from yours. I ended up using his method [1]: http://jmsliu.com/2444/click-button-in-listview-and-get-item-position.html/ "here" which worked absolutely perfect for me. Anyways this was what did for those who might run into the same issue.

    STICK THIS CODE IN THE GetView() method LOCATED IN .JAVA FILE INFLATES THE XML FILE.

    Button deleteButton = (Button) customView.findViewById(R.id.deleteButton);
    deleteButton.setTag(position);
    

    Then add this into your button click listener/ onClick method

        int position = (Integer) view.getTag();
        list.remove(position);
    
        adapter.notifyDataSetChanged();
    

提交回复
热议问题