我正在使用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);