Skip to content

Instantly share code, notes, and snippets.

@tasti
Created September 20, 2014 08:39
Show Gist options
  • Save tasti/263a072913038e156b2c to your computer and use it in GitHub Desktop.
Save tasti/263a072913038e156b2c to your computer and use it in GitHub Desktop.
A debouncer for Android.
import android.os.Handler;
public class Debouncer {
private Handler handler = null;
public Debouncer() {
this.handler = new android.os.Handler();
}
public void reset() {
// Remove any previous runnable callbacks
this.handler.removeCallbacksAndMessages(null);
}
public void debounce(Runnable callback, int delay) {
this.handler.postDelayed(callback, delay);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment