Created
July 3, 2018 10:22
-
-
Save nguyenlinhnttu/9dbc6ee1590c4bbcc30b602513b6a823 to your computer and use it in GitHub Desktop.
Android Preventing Double Click On A Button
This file contains hidden or 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
private long mLastClickTime = 0; | |
... | |
// inside onCreate or so: | |
findViewById(R.id.button).setOnClickListener(new OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
// mis-clicking prevention, using threshold of 1000 ms | |
if (SystemClock.elapsedRealtime() - mLastClickTime < 1000){ | |
return; | |
} | |
mLastClickTime = SystemClock.elapsedRealtime(); | |
// do your magic here | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment