I want to capture the onClick event when the user selects a spinner value.
I've tried implementing OnClickListener
and using the following code:
@Override
public void onClick(final View view) {
if (view == countrySpinner) {
Toast.makeText(this, "Override OK!", 3);
}
}
And binding with:
countrySpinner.setOnClickListener(this);
This compiles, but I get a RuntimeException
advising me to use OnItemClickListener
rather than OnClickListener
for an AdapterView
.
How can I capture that onClick event?
Don't treat a spinner like a button, buttons have onClick events. Spinners have onItemSelected events.
You should be capturing the Spinner's onItemSelected event like this:
Instead of setting the spinner's OnClickListener,try setting OnTouchListener and OnKeyListener.
and the listeners: