Last active
May 29, 2021 00:42
-
-
Save yava555/f05e952ca9d2c37494f86c0dd54efb0d to your computer and use it in GitHub Desktop.
Prevent double click
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
import android.view.View; | |
public abstract class OneClickListener implements View.OnClickListener { | |
private long lastClickTime = 0; | |
private static long DIFF = 1000; | |
@Override | |
public void onClick(View v) { | |
if (!isFastDoubleClick()) { | |
doClick(v); | |
} | |
} | |
/** | |
* Determine whether double-click quickly | |
* | |
* @return | |
*/ | |
public boolean isFastDoubleClick() { | |
long time = System.currentTimeMillis(); | |
long timeD = time - lastClickTime; | |
if (lastClickTime > 0 && timeD < DIFF) { | |
return true; | |
} | |
lastClickTime = time; | |
return false; | |
} | |
public abstract void doClick(View v); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment