Javatpoint Logo
Javatpoint Logo

Android Swipe to Delete RecyclerView items with UNDU

In this tutorial, we will create the example to delete an item of RecyclerView by swiping the item with undo functionality. For this purpose, we will use ItemTouchHelper class which is added in Android Support Library V7. This class is used to create a swipe to delete the items of RecyclerView. It has a SimpleCallback class that configures the events which are performed to swipe or move the item of the RecyclerView.

ItemTouchHelper class

It is a utility class which provides the facility to add swipe to dismiss and drag & drops the items of RecyclerView. It overrides the callback methods onMove() or onSwipe() depending upon the functionality we implement.

Android Swipe to Delete RecyclerView items Example

Create a class with the following code.



Create a layout regular_item.xml which appears at normal mode.


Create a layout swipe_item.xml which appears at the period of swipe item.



Create a utility class which extends the ItemTouchHelper.SimpleCallback class and overrides its onMove(), onSwiped(), onChildDraw() methods. The onSwiped() method is called when we perform swipe operation on an item, and the onChildDraw() methods contain the implementation logic of drawing canvas while swiping the items of RecyclerView.

Create an class and extends RecyclerView.ViewHolder.

Create an adapter class which extends the RecyclerView.Adapter class and overrides its onCreateViewHolder(), onBindViewHolder() methods.

Create a class and extends the Fragment class. In this class, set the adapter class and utility class.






Android Swipe to Delete RecyclerView items with UNDU Android Swipe to Delete RecyclerView items with UNDU Android Swipe to Delete RecyclerView items with UNDU

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA