Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


How to detect open and closing a Spinner?

I have a project in which I insert some values on a Spinner. These items are generated in my JAVA class and usually are a lot of values. I needed to place a placeholder, a hint, so I tried android:prompt on the XML layout, which did not work.

I did it by setting the placeholder text on the last element of the list and don't showing it, however, the setSelected() is pointing to it and so, when I open the dropdown the focus is on the end of the list and not on the beginning.

I then wanted to put the focus on the beginning, so I inserted an OnTouchListener in the Spinner and I can catch when a person opens the Spinner, but not when a person closes it and I need this action form my implementation.

Does anyone know how can I detect when a person closes the Spinner? (the onNothingSelected()doesn't work)

Or does anyone know about an alternative solution to the placeholder and focus on the first item of the list problem?