小编Sek*_*991的帖子

RecyclerView通过itemTouchHelper拖放,拖动时快速拖动

我一直在关注这个链接的指南"使用RecyclerView拖动和滑动 - 由IPaulPro",我在某些情况下遇到的问题很少.

所以,我基本上完成了他解释的所有内容+我在项目中添加了一个TextView,表示RecyclerView中项目的位置,如下所示: 在此输入图像描述

一切都很好看,除非我开始"快速射击"物品,然后我有两个问题:

  1. 它碰巧有数字的重复. 在此输入图像描述

    我所做的也是notifyAdapterSetChanged()onItemClear()方法中使用- 它以某种方式修复它,但导致了 IllegalStateException捕获 - 会导致 IndexOutOfBounds异常.

  2. 有时,当刷得太快时,物品进入"背景".只有当项目大小不同时才能看到这一点. 在此输入图像描述

我将在下面粘贴我的整个适配器代码,其中必须存在缺陷.

LayoutInflater inflater;
Context context;
AndroidEntityQuestionResult androidEntityQuestionResult;
ArrayList<AndroidEntityAnswer> list = new ArrayList<>();
ORDLayoutManagerQuestion ord;
ScreenDimensionsConstants sdc;


public OrderingRecycleAdapter(Context context, AndroidEntityQuestionResult androidEntityQuestionResult, ORDLayoutManagerQuestion ord) {
    inflater = LayoutInflater.from(context);
    this.context = context;
    this.list = androidEntityQuestionResult.getAndroidEntityQuestion().getEntityAnswer();
    this.androidEntityQuestionResult = androidEntityQuestionResult;
    this.ord = ord;
    sdc = new ScreenDimensionsConstants(context);
}

@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view = inflater.inflate(R.layout.custom_row_ordering_rv, parent, false);
    final …
Run Code Online (Sandbox Code Playgroud)

android drag-and-drop android-recyclerview

10
推荐指数
1
解决办法
3889
查看次数