I have a spinner which is populated from the database. So if the spinner is clicked with no items in it,a spinner with an empty list item is shown.I want to avoid showing the spinner when it is empty and show a toast message. I have the logic to check the count of the items and show the toast message, but I cannot find out where to call the function.What is the event called when clicking the spinner and loading the spinner items?
Share
Spinneris a subclass ofView, so,View.setOnClickListener()can be used to changeonClick()implementation which will be called when it is clicked. You can overrideonClick()to check if theSpinneris empty and then show theToast.Correction:
Since you cannot
setOnClickListenerforSpinner, you can use the solution suggested in this question (the contents of which I’ve pasted below).Instead of setting the spinner’s OnClickListener, we are setting OnTouchListener and OnKeyListener.
and the listeners: