Avoid button multiple rapid clicks

前端 未结 20 1462
猫巷女王i
猫巷女王i 2020-11-28 02:55

I have a problem with my app that if the user clicks the button multiple times quickly, then multiple events are generated before even my dialog holding the button disappear

20条回答
  •  孤城傲影
    2020-11-28 03:15

    Just a quick update on GreyBeardedGeek solution. Change if clause and add Math.abs function. Set it like this:

      if(previousClickTimestamp == null || (Math.abs(currentTimestamp - previousClickTimestamp.longValue()) > minimumInterval)) {
            onDebouncedClick(clickedView);
        }
    

    The user can change the time on Android device and put it in past, so without this it could lead to bug.

    PS: don't have enough points to comment on your solution, so I just put another answer.

提交回复
热议问题