Mohammed Atif Mohammed Atif - 1 year ago 90
Android Question

How to control swipe to dismiss for individual list item in RecyclerView

I am using two

objects, one for LEFT swiping and corresponding operations and another for RIGHT swiping and corresponding operations. In my list, few items must have only left swiping enabled and few must have only right swiping enabled.

But the problem is if I attach my
to both the Helper objects, then each object is swipe-able on both the direction.

Is there any method to control individual list items for Swipe to Dismiss in ItemTouchListener?

P.S. not interested in external libraries

Answer Source

Use ItemTouchHelper.Callback.getMovementFlags(...) (or alternatively ItemTouchHelper.SimpleCallback.getSwipeDirs(...)). It gets the ViewHolder as parameter.

Set a flag on the ViewHolder in RecyclerView.Adapter.onBindViewHolder(...) if the represented item can be swiped left or right or none. Query that flag in the above mentioned method(s) and return an according value.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download