转载请注明转自:[noyet12的博客](http://blog.csdn.net/u012975705) 博客原址:http://blog.csdn.net/u012975705/article/details/50060887
在点击时设置时间标志,判断2次点击的时间差,自定义一个时间间隔SPACE_TIME,做判断:当2次点击的时间差大于SPACE_TIME时才能出发点击。Demo源码如下。
工具类: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; }}
使用方式:/** * 订单日志 */ 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下。(∩_∩)