Swipe Dismiss RecyclerView

Swipe Dismiss RecyclerView

Hello Friends, today we are going to learn an awesome functionality based on Swipe Dismiss RecyclerView. To achieve this functionality we are going to need one java class which will handle the Swipe gesture. The class you can get from this link, this is a superb class that you need to implement with your recycler view.

The java class consists of below two main things:

  1. A subclass of RecyclerView.OnItemTouchListener that listens to touch events and detects when an item is being swiped, animating it accordingly.
  2. A SwipeListener that is called in order to know if an item can be dismissed and called again when items are dismissed.

Example

In this tutorial, we are going to learn how to implement swipe dismiss functionality to RecyclerView items.

VIDEO DEMO

1. Create a new project in Android Studio by navigating to File ⇒ New ⇒ New Project and fill required details. By default my activity is MainActivity.java.

2. Open res ⇒ values ⇒ strings.xml and add below string values. These are some strings that we are going to use in our project.

3. Now open up your activity_main.xml and place the below code to it.

4. For RecyclerView row items create layout naming custom_item_row_layout.xml and place the below code to it. You can use any layout here.

5. Now create adapter class for RecyclerView naming RecyclerViewAdapter.java and add the below code to it.

6. Now open your MainActivity.java class and place the below code to it. In this class you can see the implementation of SwipeableRecyclerViewTouchListener.java class.

Full Source Code

Swipe Left to Dismiss CardView

Swipe Left to Dismiss CardView

Swipe Right to Dismiss CardView

Swipe Right to Dismiss CardView

7. Finally, create a new Java class naming SwipeableRecyclerViewTouchListener.java and place the below code to it. The below class used to handle the touch events of dismiss functionality.

8. Finally, all done. Now you can also make application using Swipe Dismiss functionality.

Thanks. 🙂

Download Source Code – >

 

 

About the author

I am an Android developer for whom Android is the one and only love. I work as a freelancer which gets me and Android closer. I always love to share my learnings and love to learn from others knowledge too.

Leave a Comment

Comment (required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

Name (required)
Email (required)