Android ButterKnife防止过快重复点击的Demo

ButterKnife防止重复点击

 @OnClick({R.id.btn_next, R.id.iv_close})
    public void onViewClicked(View view) {
        if (isFastClick()) {
            return;
        }
        switch (view.getId()) {
            case R.id.iv_close:
                break;
            case R.id.btn_next:
                break;
        }
    }

    private static final int MIN_DELAY_TIME = 1000;  // 两次点击间隔不能少于1000ms
    private static long lastClickTime;

    public static boolean isFastClick() {
        boolean flag = true;
        long currentClickTime = System.currentTimeMillis();
        if ((currentClickTime - lastClickTime) >= MIN_DELAY_TIME) {
            flag = false;
        }
        lastClickTime = currentClickTime;
        return flag;
    }
展开阅读全文

没有更多推荐了,返回首页