androidandroid-recyclerviewnestedrecyclerview

Recycler View - disable Drag and Drop or Swipe actions for just few selected row from a list


I want to create a list, for example, To-Do List. In this User is allowed to select/unselect an item, reorder according to their priority. In the current scenario, I am able to give them all of the above functionality using ItemTouchHelper.SimpleCallback. My Challenge starts here -

I read about Method getSwipeDirs but didn't understand how to utilize it in my scenario.

I have gone through a couple of articles but all of them remove an item on swipe. Hence, I couldn't find the reference for my case.

If anyone has an idea about it and guide me further then it would be a great help! I am open

Note: I have used com.daimajia.swipe.SwipeLayout library just for left swipe as I want to enable full swipe just for Right direction. I am able to disable the library swipe by utilizing some of its methods. However, I still can not disable Drag/Drop or Right Swipe which I am using with help of ItemTouchHelper.SimpleCallback.


Solution

  • We can simply add the tag to the viewHolder of recyclerView and fetch the info from the tag for any particular row in the getMovementFlags method of ItemTouchHelper.Callback and manipulate drag/ drop or swipe flag as needed!