What you are looking for is using an OnTouchListener
instead of the OnClickListener. This will allow you to react upon the first touch of the button and stop reacting on other button touches until the first touch is stopped again.
Android : Only one button clickable at once
Question
While developing an android app, I have an activity with some buttons. I would like the onClickListener
action to start when the user puts his finger on the screen immediately so he isn't able to click two buttons at once.
I do that in iOS by using the touchDown
event rather than the default TouchUpInside.
I have absolutely no idea of how this can be done in Android...
Android code :
button.setOnClickListener(clicked);
[...]
View.OnClickListener clicked = new View.OnClickListener() {
public void onClick(View v) {
//Cool stuff there
}
}
thanks for helping !
Solution
OTHER TIPS
You can disable the other buttons when you start the click and re-enable them when you are finished.
By default the buttons clicks will be handled on the same thread so their actions would not complete in parallel even if you do not disable them.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow