DEV Community

Pedro Massango
Pedro Massango

Posted on

1

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

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay