I tried Thread.sleep(x) and I tried
setEnabled(false); setClickable(false); But neither worked as expected. I read somewhere that the clicks are queued and therefore the previous solutions didn't worked.
Any ideas?
You could set a flag in your onClick, something like clickable = false once it's been clicked once, and then re-enable it when you want. Run the relevant onClick code only if clickable is true.
You could disable it once clicked. add in the xml a listner for the on click
<Button android:id="@+id/button1" android:layout_height = "wrap_content" android:layout_width ="wrap_content" android:text = "lets do this" android:onClick = "DoIt" /> And then disable it within the on click listner
public void DoIt(View v){ ((Button) v).setEnabled(false); ...your code... } DoIt() method queued. Once the first call gets executed, the button will be disabled, but by then it is too late and the other 2 calls to DoIt() will still occur.onClick() method is not reliable, because the Android framework queues the button click events in an event queue. onClick() methods are not called synchronously when the user clicks the button. Therefore, if the user is quick enough (or the device is slow enough), it is always possible to get multiple click events in the queue before the first onClick() method is called.