-3

I got a requirement that I have a button and when user presses it continuously, I have to wait till the user gives 2 second gap. When the gap is there then I have to do a network hit. I am thinking to start timer for first click and when next click happens with in less than 2 seconds, I can stop it and start from beginning. But I don't feel like its a good idea. Any other ideas please?

Thanks in advance.

Kameswari
  • 738
  • 7
  • 27
  • 1
    I think you can disable the button when you are making network call and enable it back after you got response or after your time limit exceeds. – Uma Sankar Dec 11 '18 at 11:51
  • What is the context for the network request if it is somthing like submit you would want to click the button only once. in that case disabling the button when you start the network request and enabling it again when the request is done might be a good idea. If it doesn't matter how many requests you send they just need to be 2 seconds apart, you would want something like debounce. Debounce the events of click for 2 seconds. Duplicate of [ https://stackoverflow.com/questions/16534369/avoid-button-multiple-rapid-clicks ] – Raunak Sett Dec 11 '18 at 12:10
  • In order to reduce the load on server with multiple continuous hits, the requirement came to handle consecutive clicks at application side. – Kameswari Dec 11 '18 at 12:28

1 Answers1

0

I have achieved this with CountDownTimer API which is available in Android SDK. Thanks for all your support.

Kameswari
  • 738
  • 7
  • 27