Disable Swipe for position in RecyclerView using ItemTouchHelper.SimpleCallback

前端 未结 7 632
面向向阳花
面向向阳花 2021-01-30 02:44

I am using recyclerview 22.2.0 and the helper class ItemTouchHelper.SimpleCallback to enable swipe-to-dismiss option to my list. But as I have a type of header on it, I

7条回答
  •  感情败类
    2021-01-30 03:31

    If someone is using ItemTouchHelper.Callback. Then You can remove any related flags in getMovementFlags(..) function.

    @Override
    public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
        int dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN;
        int swipeFlags = ItemTouchHelper.START | ItemTouchHelper.END;
        return makeMovementFlags(dragFlags, swipeFlags);
    }
    

    Here instead of dragFlags and swipeFlags You can pass 0 to disable corresponding feature.

    ItemTouchHelper.START means swiping left to right in case of left to right locale (LTR application Support), but the other way around in a right to left locale (RTL application Support). ItemTouchHelper.END means swiping in the opposite direction of START.

    so you can remove any flag according to your requirements.

提交回复
热议问题