How to prevent rapid double click on a button

后端 未结 11 1266
野的像风
野的像风 2021-01-01 19:12

I have looked at the answers here - Android Preventing Double Click On A Button and implemented qezt\'s solution like and I\'ve tried setEnabled(false) like so

11条回答
  •  Happy的楠姐
    2021-01-01 19:38

    Qezt solution is already fine. But if you want to prevent super fast double-click, then you simply reduce the threshhold

        // half a second
        if (SystemClock.elapsedRealtime() - doneButtonClickTime < 500) {
            return;
        }
    
        // or 100ms (1/10 of second)
        if (SystemClock.elapsedRealtime() - doneButtonClickTime < 100) {
            return;
        }
    

提交回复
热议问题