Skip to content

Instantly share code, notes, and snippets.

@blipinsk
Last active September 30, 2017 08:11
Show Gist options
  • Save blipinsk/5de06dcf975f872a26aef806a604a097 to your computer and use it in GitHub Desktop.
Save blipinsk/5de06dcf975f872a26aef806a604a097 to your computer and use it in GitHub Desktop.
[Medium] Butterknife's DebouncingOnClickListener as abstract class
public abstract class DebouncingOnClickListener implements View.OnClickListener {
static boolean enabled = true;
private static final Runnable ENABLE_AGAIN = new Runnable() {
@Override
public void run() {
enabled = true;
}
};
public abstract void doClick(View v);
@Override
public final void onClick(View v) {
if (enabled) {
enabled = false;
v.post(ENABLE_AGAIN);
doClick(v);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment