Swipe Callback for Recycler View

Andrea
1 min readAug 15, 2019

--

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 :

  1. Create your desired Recycler View and its item
  2. Create class extension of ItemTouchHelper.SimpleCallback
  3. Attach the Swipe Callback to your Recycler View

— — — — —

  1. 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

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Andrea
Andrea

No responses yet

Write a response