Double click listener on Android

pedromassango

Pedro Massango

Posted on December 22, 2022

Double click listener on Android

cover

Some times we need to check when the user made a double click in some of our android views. To solve this problem I made a small library to handle this.
How to use?
Using Android Studio, just add this line in your build.gradle project level:

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' } // add this line
    }
}
Enter fullscreen mode Exit fullscreen mode

Second, add this line inside dependencies on your app build.gradle module level:
implementation 'com.github.pedromassango:doubleClick:v3.0'
The class DoubleClick extends from View.OnClickListener so, just call the DoubleClick class on you onClickListener of the view that you wish to listen, and pass a instance of DoubleClickListener class to listen the events.

Button btn = new Button(this);
btn.setOnClickListener( new DoubleClick(new DoubleClickListener() {
            @Override
            public void onSingleClick(View view) {

                // Single tap here.
            }

            @Override
            public void onDoubleClick(View view) {

                // Double tap here.
            }
        });
        //  use this to define your own interval
        //  }, 100));
Enter fullscreen mode Exit fullscreen mode

OBS: On the latest version you can define your own interval!
To know more, check it on GitHub:
https://github.com/pedromassango/doubleClick

💖 💪 🙅 🚩
pedromassango
Pedro Massango

Posted on December 22, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Launch new Activity(Intent)
android Launch new Activity(Intent)

September 22, 2024

Double click listener on Android
android Double click listener on Android

December 22, 2022