Created
June 13, 2014 14:36
-
-
Save sinergy/26005d6f6a9a049ce5f1 to your computer and use it in GitHub Desktop.
This class allows a single click and prevents multiple clicks on the same button in rapid succession.
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
/** | |
* This class allows a single click and prevents multiple clicks on | |
* the same button in rapid succession. Setting unclickable is not enough | |
* because click events may still be queued up. | |
* | |
* Override onOneClick() to handle single clicks. Call reset() when you want to | |
* accept another click. | |
*/ | |
public abstract class OnOneClickListener implements View.OnClickListener { | |
private boolean clickable = true; | |
@Override | |
public void onClick(View view) { | |
if (clickable) { | |
clickable = false; | |
onOnClick(view); | |
} | |
} | |
/** | |
* Override this function to handle clicks. | |
* reset() must be called after each click for this function to be called again | |
* @param view | |
*/ | |
public abstract void onOnClick(View view); | |
/** | |
* Allows another click. | |
*/ | |
public void reset() { | |
clickable = true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment