如何在Recyclerview中将所选项目的位置更改为顶部? [英] How to change selected item position to top in Recyclerview?

查看:85
本文介绍了如何在Recyclerview中将所选项目的位置更改为顶部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有recyclerview,我想在选择recyclerview的项目后将项目的位置动态更改为顶部.

I have recyclerview in that I want to change item's position dynamically to top after selecting the item of recyclerview.

请提出解决上述问题的最佳方法?

Please suggest best way to achieve the above problem?

推荐答案

您需要将选定的项目与列表中的顶部项目交换,然后将位置更改通知您的适配器. 示例代码如下:

You need to swap selected item with top item in list, then notify your adapter about position change. A sample code would look like:

Collections.swap(orderItems.getItems(), position, 0);
                notifyItemMoved(position, 0);

希望有帮助!

这篇关于如何在Recyclerview中将所选项目的位置更改为顶部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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