Created
September 20, 2014 08:39
-
-
Save tasti/263a072913038e156b2c to your computer and use it in GitHub Desktop.
A debouncer for Android.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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