Is it possible to know whether a Spinner
is open or closed? It would even be better if there was some sort of onOpenListener for Spinners.
I've tried using an OnItemSelectedListener like this:
spinnerType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
executeSomething();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
Log.d("nothing" , "selected");
}
});
I can know that the window will close if something is selected (in executeSomething()). But I don't get notified if I click outside of the Dialog, which also closes the spinner
Another option to watch for those events is to extend the
Spinner
class and use one of its methods(performClick()
which will trigger its dialog/popup) followed by monitoring the focus of the window holding this customSpinner
. This should provide you with the wanted closed event for all the possible finishing possibilities(for either the dialog or dropdown mode).The custom
Spinner
class: