简体   繁体   English

无法删除recyclerview项目

[英]Unable to delete recyclerview item

In my recylerview item, there is an option to delete the item. 在我的recylerview项目中,有一个删除项目的选项。 I am trying to achieve it in this way from activity class : 我正在尝试通过活动类以这种方式实现它:

list.remove(position);
recyclerView.removeViewAt(position);
adapter.notifyItemRemoved(position);
adapter.notifyItemRangeChanged(position, list.size());

But I am getting the following error : 但是我收到以下错误:

java.lang.NoSuchMethodError: No virtual method notifyItemRemoved(I)V in class RecyclerviewAdapter

What is wrong here? 怎么了

Do not try to remove it by getting a position in Recycler view. 不要试图通过在“回收站”视图中找到位置来删除它。 Please refer any unique id or unique attribute of that element for it. 请为其引用任何唯一ID或该元素的唯一属性。 If there are no unique elements in your objects in recycling view, please add the unique id. 如果在回收视图中对象中没有唯一元素,请添加唯一ID。

Then get unique id when the user clicks an item in recycle view. 然后,当用户在回收视图中单击某个项目时,便获得唯一的ID。 After that search through whole the list and delete a relevant item from a list using a unique id 之后,搜索整个列表,并使用唯一ID从列表中删除相关项目

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM