Double click listener on Android
Pedro Massango
Posted on December 22, 2022
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
}
}
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));
OBS: On the latest version you can define your own interval!
To know more, check it on GitHub:
https://github.com/pedromassango/doubleClick
Posted on December 22, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.