Android限制按钮多次点击

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;
    }

使用

//点击事件
        findViewById(R.id.bt).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 进行点击事件后的逻辑操作
                if (isFastClick()) {
                    Toast.makeText(MainActivity.this, "点击过快请稍后点击哦~", Toast.LENGTH_SHORT).show();
                    return;
                } else {
                    Toast.makeText(MainActivity.this, "正常执行", Toast.LENGTH_SHORT).show();
                }
            }
        });

你可能感兴趣的:(Android限制按钮多次点击)