Android Listview Swipe To Delete Example Tutorial Step By Step

Android Listview Swipe To Delete Tutorial With Example guide you to make a listview swipe to show delete button.

We will make a listview in which listview row item will be deleted when swipe left or right.

At the end of this example, you will learn to make a listview feature of swipe to delete like in gmail app.

First checkout the output video, then we will develop the example step by step.

Download Source Code For Android Listview Swipe To Delete

Click on below link to get android studio source code.

Step 1. Make a new project.

Create a new project in android studio with empty activity.

Step 2. Adding dimens file

Create a new xml file named dimens.xml under res -> values folder

Add following code in it

Step 3. Updating colors.xml

Update colors.xml file with below

Step 4. Create listview row layout

Make a new layout resource file and give it a name list_item.xml

Add below source code in it

Step 5. Add Library to build.gradle(Module: app)

Add below line into build.gradle(Module: app) file

We have used external library in this example.

Visit library on github here.

Step 6. Adding Images

download this images and add to drawable folder

Now put these images in the drawable folder.

You can learn how to add items to the drawable folder here in step 2. (No need to create xml file in drawable, just copy and paste images in drawable).

Step 7. Making Model

Create a new java class named Model.java and add below code

Step 8. Preparing Custom Adapter

Make a new java class with name CustomAdapter.java

Add following into it

Step 9. Updating Main Activity

Update activity_main.xml as below

Update MainActivity.java file as below

Understanding the main logic

Look closely at following snippet from Main Activity

Above code is the heart of this example.

Row item of listview is removed when user swipes left or right. onDismiss() method will be executed when user swipes.

You can add your code as per your requirements in this method.

So that is all for android listview swipe to delete tutorial with example.

You can ask your queries in comment without any hesitation.

Thank you and keep sharing our tutorials.

Hardik Parsania

I am mobile app developer. I am always passionate about solving complex and real world problems.I have developed many apps with great interest and superior logical skills.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *