A normal android Spinner will pop up a list of choices when clicked. I want to override this onClick. When the user clicks the spinner during certain error states, I want to display an error message rather than pop up the list of choices. Currently, all I can do is set a OnClickListener, but its onClick method doesn't let me prevent the list of options from appearing.
Try setting a onTouchListener
and in the onTouch
method display your popup and return true
to consume the event and stop it from propagating to the view (Spinner in this case).
spinner.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// display your error popup here
return true;
}
});
This should stop the "drop down list" from appearing.
Edit: forgot to mention you could do your error state check in the onTouch
method as well, so you don't completely disable the spinner.
Extends from Spinner and override performClick() like this:
@Override
public boolean performClick() {
if(errorOccured) {
// show validation message
return true; // the event is handled by ourselves
}
else {
return super.performClick(); // show spinner dialog
}
}
See sources for more details. Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With