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

Android Which Animal Are You?

Is there any way to have a default value in a spinner that's not selectable? That is, like a title?

I would like my spinners to show "Choose an Option" at startup. And i would like this "title" not to show up in the dropdown list. I also want to use this in the code to see if people missed making a choice. At which time, I can prompt them to make a choice.

1 Answer

Ben Deitch
STAFF
Ben Deitch
Treehouse Teacher

Hey Sue!

That is possible, but unfortunately it's not super easy. Spinners weren't designed to support having a default unselectable value, so we have to 'hack' it in. Here's a really good Stack Overflow post that contains a few possible solutions. And as another option, I think in the past I've just placed a TextView over the Spinner and made the TextView unclickable (in XML android:clickable="false"). That way it looks like a title on the Spinner even though it's not.

Hope that helps! Ben

Thanks, Ben. I'll check it out.