In your onClickListener for the button:
myButton.setEnabled(false); Timer buttonTimer = new Timer(); buttonTimer.schedule(new TimerTask() { @Override public void run() { runOnUiThread(new Runnable() { @Override public void run() { myButton.setEnabled(true); } }); } }, 5000);
This will turn off the button when pressed and turn it back on after 5 seconds.
If the click event is handled in a class that extends the view, and not in Activity, do the same, but replace runOnUiThread with post .
Tofferj
source share