How to prevent rapid double click on a button

后端 未结 11 1219
野的像风
野的像风 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条回答
  •  迷失自我
    2021-01-01 19:45

    Suru's answer worked well for me, thanks!

    I'd like to add the following answer for anybody who's using https://github.com/balysv/material-ripple/blob/master/library/src/main/java/com/balysv/materialripple/MaterialRippleLayout.java and is facing this problem -

    app:mrl_rippleDelayClick is true by default. This means, onClick will be executed only after it's finished showing the ripple. Hence setEnabled(false)inside onClick will be executed after a delay because the ripple isn't done executing and in that period you may double click the view.

    Set app:mrl_rippleDelayClick="false" to fix this. This means the call to onClick will happen as soon as the view is clicked, instead of waiting for the ripple to finish showing.

提交回复
热议问题