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

👋 Kindness is contagious

Please leave your appreciation by commenting on this post!

It takes one minute and is worth it for your career.

Get started

Let's be a part of something!

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

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay