我已经使用itemtouchhelper类在recycler视图中实现了drag item,它工作得很好,但是当我在活动之间切换时,项目位置会返回到默认位置。我希望即使在切换活动时,回收者查看项目的位置也保持不变。
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;
}
暂无答案!
目前还没有任何答案,快来回答吧!