从RecyclerView删除行 [英] Remove row from RecyclerView

查看:79
本文介绍了从RecyclerView删除行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

借助本文,我已经以某种方式实现了回收视图,现在我的要求是在运行时从此回收视图中删除一行.

I have somehow implemented recycle view with the help of this post, now my requirement is to remove a row at runtime from this Recycle View.

链接- http://treyrobinson.net/blog/android-l-tutorials-part-3-recyclerview-and-cardview/

请帮助我.

谢谢.

推荐答案

由于我们不知道您的适配器如何,并且鉴于该链接中的信息,您可以在适配器中创建一个删除对象的方法:

Since we don't know how is your adaper and given the info in that link you can create a method in the adapter that removes an object:

public void removeItem(int position) {
       mData.remove(position);
       notifyItemRemoved(position);
}

您可以通过自己的活动来完成所有这些操作,例如:

You can all this from your activity like:

((MyRecyclerAdapter)myRecyclerView.getAdapter()).removeItem(position);

这篇关于从RecyclerView删除行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆