问题描述
我已经使用 itemtouchhelper 类在回收器视图中实现了拖动项目,它运行良好,但是当我在活动之间切换时,项目位置返回到默认值。我希望回收者视图项目位置即使在活动切换时也保持不变。
public RecyclerViewitemtouchhelper(Context context,RecyclerView recyclerView) {
super(itemtouchhelper.UP | itemtouchhelper.DOWN |
itemtouchhelper.START | itemtouchhelper.END,itemtouchhelper.LEFT);
this.recyclerView = recyclerView;
this.context = context;
}
@Override
public boolean onMove(@NonNull RecyclerView recyclerView,@NonNull RecyclerView.ViewHolder viewHolder,@NonNull RecyclerView.ViewHolder target) {
int fromPosition = viewHolder.getAbsoluteAdapterPosition();
int toPosition = target.getAbsoluteAdapterPosition();
Collections.swap(MainActivity.dataArrayList,fromPosition,toPosition);
recyclerView.getAdapter().notifyItemmoved(fromPosition,toPosition);
return false;
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)