滑动以消除在RecyclerView中不起作用的情况

时间:2019-10-01 17:49:03

标签: android-recyclerview itemtouchhelper

我正在使用ItemTouchHelper.SimpleCallback向左/向右滑动并从RecyclerView Adapter中删除该项目。

尽管刷卡对项目没有影响,但每次尝试交换时,我也注意到logcat中的以下消息。

W/Choreographer: OPTS_INPUT: First frame was drawed before optimized, so skip!
W/Choreographer: OPTS_INPUT: First frame was drawed before optimized, so skip!
W/Choreographer: OPTS_INPUT: First frame was drawed before optimized, so skip!
W/Choreographer: OPTS_INPUT: First frame was drawed before optimized, so skip!
W/Choreographer: OPTS_INPUT: First frame was drawed before optimized, so skip!
W/Choreographer: OPTS_INPUT: First frame was drawed before optimized, so skip!
W/Choreographer: OPTS_INPUT: First frame was drawed before optimized, so skip!

我的猜测是它与性能问题有关,但不确定这是否会导致滑动无效?

如果有人能帮忙弄清楚这里出了什么问题,那真是太好了?

这是我的ItemTouchHelper.SimpleCallback班。

public class SwipeToDismissCallback extends ItemTouchHelper.SimpleCallback {

private Context mContext;

SwipeToDismissCallback(@NonNull Context context) {
    super(0, ItemTouchHelper.RIGHT);
    this.mContext = context;
}

@Override
public boolean onMove(@NonNull RecyclerView recyclerView,
                      @NonNull RecyclerView.ViewHolder viewHolder,
                      @NonNull RecyclerView.ViewHolder target) {
    return false;
}

@Override
public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) {
    Toast.makeText(mContext, "Hey there, this is swiped...", Toast.LENGTH_SHORT).show();
 }
}

在我的Fragment班上:

SwipeToDismissCallback swipeToDismissCallback =
            new SwipeToDismissCallback(Objects.requireNonNull(getActivity()));
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(swipeToDismissCallback);
itemTouchHelper.attachToRecyclerView(recyclerView);

0 个答案:

没有答案