防止按钮多次点击 发表于 2020-05-11 | 分类于 轮子 | 阅读量 防止按钮多次点击1234567891011121314151617181920212223242526272829303132333435363738394041public class ButtonUtils { private static long lastClickTime = 0; private static long DIFF = 1000; private static int lastButtonId = -1; /** * 判断两次点击的间隔,如果小于1000,则认为是多次无效点击 * * @return */ public static boolean isFastDoubleClick() { return isFastDoubleClick(-1, DIFF); } /** * 判断两次点击的间隔,如果小于1000,则认为是多次无效点击 * * @return */ public static boolean isFastDoubleClick(int buttonId) { return isFastDoubleClick(buttonId, DIFF); } /** * 判断两次点击的间隔,如果小于diff,则认为是多次无效点击 * * @param diff * @return */ public static boolean isFastDoubleClick(int buttonId, long diff) { long time = System.currentTimeMillis(); long timeD = time - lastClickTime; if (lastButtonId == buttonId && lastClickTime > 0 && timeD < diff) { Log.v("onClick", "isFastDoubleClick短时间内按钮多次触发"); return true; } lastClickTime = time; lastButtonId = buttonId; return false; }} -------------本文结束感谢阅读------------- 打赏 微信支付 支付宝