在动态更新的回收者视图中滑动以关闭

Swipe to dismiss in dynamically updated recycler view

所以我切换到 Recycler View 并使用 ItemTouchHelper 来添加移动和关闭项目的功能。

然而,我的回收站视图中的所有项目每秒都会更新。因此,如果您正在拖动项目并发生更新,动画将重置。

有没有简单的方法来禁用更新,或者更好的是,在调用 notifyDataSetChanged() 后禁用回收器视图项目的重新定位?

我如何更新 Recycler View:我有一个调用 notifyDataSetChanged() 的 Timer 对象;每秒。

能不能在拖动时避免调用notifyDataSetChanged?

我是这样解决问题的:

  1. 将 "boolean moving" 添加到我的自定义 recyclerview 适配器 class,每次任何项目被设置为 "true" dragged\swiped
  2. Timer 现在调用我的自定义方法 adapter.update() 而不是 adapter.notifyDataChanged()

    public无效更新(){ 如果(!移动)notifyDataSetChanged(); }

现在可以正常使用了