DEV Community

Pedro Massango
Pedro Massango

Posted on


Double click listener on Android


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 '' } // 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() {
            public void onSingleClick(View view) {

                // Single tap here.

            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:

Top comments (0)

An Animated Guide to Node.js Event Loop

>> Check out this classic DEV post <<