Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save wutianlong/588f8061579cd33461078919912f1685 to your computer and use it in GitHub Desktop.
Save wutianlong/588f8061579cd33461078919912f1685 to your computer and use it in GitHub Desktop.
DoubleClick----RxJava
public void doubleClickDetect(View view){
Observable<Void> observable = RxView.clicks(view).share();
observable.buffer(observable.debounce(200, TimeUnit.MILLISECONDS))
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Action1<List<Void>>() {
@Override
public void call(List<Void> voids) {
if(voids.size() >= 2){
//double click detected
}
}
}, new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
Timber.e(throwable, "error");
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment