maxib7 maxib7 - 2 months ago 10x
Java Question

setOnItemSelectedListener error when using 3rd party library's spinner

I'm using ( library. Before I used it I had an activity where the user selected options from spinners. It worked fine and I wanted to use his spinner instead. I ran into one problem. When I call setOnItemSelectedListener, I get this error message in the editor

setOnItemSelectedListener (com.rey.material.widget.Spinner.setOnItemSelectedListener) in Spinner cannot be applied to (anonymous android.widget.AdapterView.setOnItemSelectedListener)

here is my java file:
(the error spot is at line 123)

here is my xml:
(I haven't applied it to all spinners yet only the first one)


After a lot more digging around and experimenting, I found an answer to my problem.

To anyone in the future with a similar problem with setOnItemSelectedListener with 3rd party spinners, here is the solution I found to work for me.

instead of having

spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()

you need to instead put

spinner.setOnItemSelectedListener(new Spinner.OnItemSelectedListener()

I get no errors and can save the item the user selected just fine