Tips for preventing repeated clicks in Android
Set the time flag when you click to determine the time difference between two clicks, and customize a time interval SPACE_TIME. Make a judgment: when the time difference between two clicks is greater than SPACE_TIME, you can start to click. The Demo source code is as follows.
Tool: package com. plusub. renthostapp. util;/*** package: com. plusub. renthostapp. util * Created by noyet on 2015/11/26. */public class NoDoubleClickUtils {private static long lastClickTime; private final static int SPACE_TIME = 500; public static void initLastClickTime () {lastClickTime = 0;} public synchronized static boolean isDoubleClick () {long currentTime = System. currentTimeMillis (); boolean isClick2; if (currentTime-lastClickTime> SPACE_TIME) {isClick2 = false;} else {isClick2 = true;} lastClickTime = currentTime; return isClick2 ;}}
Usage:/*** order log */private View. OnClickListener logListener = new View. OnClickListener () {@ Override public void onClick (View view) {if (! NoDoubleClickUtils. isDoubleClick () {EventBus. getDefault (). post (new RefreshEvent (RefreshEvent. RefreshType. TYPE_LAND_ORDER_LOG, view. getTag ()));}}};
Mark it first. (Partition _ Partition)