Create your account

Already have an account? Login here

Note: By joining, you will receive periodic emails from Coursetro. You can unsubscribe from these emails.

Create account

76. Implement Swipe To Delete

Design + Code an Android App from Scratch

Woah, wait a second..

Scrounge up some loose change to become a pro member, or login to your account to view this lesson.

Alright, join now. Or login to your account if you're already a pro member.

This video shows how to implement Swipe to Delete for RecyclerView using the itemTouchHelper.Callback interface. In the first step we create a class that extends from ItemTouchHelper.Callback. Override the getMovementFlags to call makeMovementFlags where we specify the dragFlags and swipeFlags. In our case, we don’t support dragging and hence return 0 and for the swipe flags we specify ItemTouchHelper.END to indicate that our RecyclerView should be capable of being swiped from left to right in most languages and right to left while the user is using Arabic or Hebrew. To disable dragging, return false from the isLongPressDragEnabled method and to enable swiping return true from the isItemViewSwipeEnabled. Finally override the onSwipe method and forward the event to the RecyclerView.Adapter where we can delete the item from the database by calling the removeFromRealm method and notifyDataSetChanged method to refresh the RecyclerView.

Course Cirriculum