Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nguyenlinhnttu/9dbc6ee1590c4bbcc30b602513b6a823 to your computer and use it in GitHub Desktop.
Save nguyenlinhnttu/9dbc6ee1590c4bbcc30b602513b6a823 to your computer and use it in GitHub Desktop.
Android Preventing Double Click On A Button
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