Android Swipe Gesture

Android Swipe Gesture

The Android SDK supports a variety of gestures you can detect, allowing you to tailor the ways in which users interact with your applications. In this tutorial, we will look at the framework that allows developers to add gesture detection to a simple application, working through the process of supporting the fling gesture and outlining how to support other gestures. Once you’ve completed the development for a basic fling function, you’ll be able to add additional gestures to the application yourself.


In this tutorial, we are going to learn how to implement various swipe gestures in an app.

Video Demo

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

2. First create an xml layout file naming activity_main.xml that contains several imageview indicating type of gestures that a user can do.

3. Now create a java class naming that conatins various Gesture detector methods that we can use in our activity to recognize user gesture. You can modify this class according to your need.

4. Finally come to your and add the following code. In this class we do several things listed below:

  • Implement SimpleGestureListener interface to listen user gesture.
  • Make an instance of SimpleGestureFilter class that we had created above.
  • Finally use onSwipe(int direction) and onDoubleTap method to do your stuff.
5. Now, you are all done, run your app and you will get the output as shown in video.

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.


How can we use this for Fragment?

    Hi Eswar,

    In fragment wherever you want to use Activity as Context you can use getActivity().



Hello. How can we save this gestures in database?

    Hi Azriidros

    In post we are displaying a toast whenever a gesture is detected. So there you have to save the gesture details in database.

    If you don’t have any knowledge about Sqlite database then check this link.


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)