If you only need to restore the standard click behaviour, this is a simpler and more compact version of Jordi's answer:
spinner.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
v.performClick();
}
return true;
}
});
Further thoughts
This behaviour has also been annoying me. After investigation, it seems like it has a name: drag to open. You can see how it's defined in the source of the AppCompatSpinner#onTouchEvent()
method.
Some problems I see with this forced behaviour (and the reason for which some people want to disable it):
- It allows the user to selects disabled values in the spinner. By long-pressing, dragging and releasing, you can select values which would not even be selectable with a normal interaction (click-to-open + click-to-select)
- As a consequence of #1, it can also make Espresso test fail very easily. Indeed, in Espresso, the duration of a click is rather unstable and one tap can quickly turn into a long-press-and-select-interaction.
- Finally, the biggest problem here is that there is no method / XML attribute to disable the "drag to open" behaviour...
Let's have it fixed!
I've opened a ticket related to this on the AOSP issue tracker: #228953. Feel free to follow it, or to comment if I missed anything.