Last active
September 30, 2017 08:11
-
-
Save blipinsk/5de06dcf975f872a26aef806a604a097 to your computer and use it in GitHub Desktop.
[Medium] Butterknife's DebouncingOnClickListener as abstract class
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
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