-3

I want to know if there is a specific reason why you cannot use OnItemClickListener with a spinner in Android? Looking through older posts ( setOnItemClickListener Not Works with Spinner and I have an error: setOnItemClickListener cannot be used with a spinner, what is wrong?) it seems as though people don't even bother with OnItemClickListener and rather go straight for OnItemSelectedListener. Why does Eclipse give OnItemClickListener as an option for a spinner if it can never work?

Some context- I'm not really too bothered by which method I use. As soon as the user selects an item from the spinner, I want to make a second spinner visible and populate it from the database based on the option selected in the first spinner. Now when I use OnItemSelectedListener, the second spinner is immediately set to visible. Is there a workaround for this?

Community
  • 1
  • 1
Code Vader
  • 739
  • 3
  • 9
  • 26
  • On question about Eclipse, I don't know; on what seems to be a programming issue about your two spinners, you might want to add some details and some code. – natario Apr 26 '15 at 11:32

1 Answers1

1

Why does Eclipse give OnItemClickListener as an option for a spinner if it can never work?

Because everything extending AdapterView has setOnItemClickListener(). Just because some subclasses ignore it does not mean that the setter magically disappears.

Is there a workaround for this?

There is no workaround, because there is no problem, because it is doing exactly what you say you want to have happen ("I want to make a second spinner visible and populate it from the database based on the option selected in the first spinner"). A Spinner always has a selection if there is data to select from. Hence, your second Spinner should always be visible, since it is "based on the option selected in the first spinner", and there will always be an "option selected in the first spinner".

It sounds like what you really want is to only have the second Spinner visible for specific selections in the first Spinner, where you set up the first Spinner where there is some selection that, in business terms if not technical terms, means "no selection". You are welcome to do this, but then you will have to implement the logic to handle this, only showing the second Spinner when an appropriate value is selected in the first Spinner.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • I am having a Spinner issue with onItemClick() in a RecyclerView list here: https://stackoverflow.com/questions/46312851/fix-onitemclick-for-recyclerview I would appreciate any thoughts or ideas you have. – AJW Sep 20 '17 at 04:10