This is from one of my task as Junior Android Developer to create Recycler View with feature when the item swipe to left or right, it will be deleted.
Turn out it is more simple than I thought. The steps will be :
- Create your desired Recycler View and its item
- Create class extension of ItemTouchHelper.SimpleCallback
- Attach the Swipe Callback to your Recycler View
— — — — —
- Create your desired Recycler View and its item.
This article will not discuss about creating Recycler View, its layout and its item. Android documentation is quite clear on this topic but sometimes I will refer to this example to refresh my memory.
2. Create class extension of ItemTouchHelper.SimpleCallback
Pretty self explanation as the title, upon creating the class that extends ItemTouchHelper.SimpleCallback it will overrides 3 methods. The methods where the action will happen after Swipe is OnSwiped
3. Attach Swipe Callback to your Recycler View
When the Swipe Callback class has been created, we can attached it to Recycler View on the Main Activity.
And that’s it ! The Recycler View item now has feature Right Swipe or Left Swipe.
Further reference for this topic : https://medium.com/@zackcosborn/step-by-step-recyclerview-swipe-to-delete-and-undo-7bbae1fce27e