转载:
工具类:
public class Utils { private static long lastClickTime; public static boolean isFastDoubleClick() { long time = System.currentTimeMillis(); long timeD = time - lastClickTime; if ( 0 < timeD && timeD < 800) { return true; } lastClickTime = time; return false; }}
控件点击的处理:
mHandler.removeCallbacks(runnable);if (!Utils.isFastDoubleClick()) { imageLoader.loadImage(MealOrderingActivity.this, path, mImageSize, options, simpListener);// imageLoader.displayImage(MealOrderingActivity.this,path, // (ImageView) mImageSwitcher.getCurrentView(),// options,simpListener); }else{ log("load from www or sd showDishes runnable before"); mHandler.postDelayed(runnable, 1000); }
这样,两次点击时间相隔小于800ms,便不会触发事件,具体的临界时间可以根据需求自己修改.
再加上一个postDelayed,确保不会由于最后两次点击时间间隔太近,导致最后一次操作也被忽略。