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

Adjust spinner dropdown height

I'm currently trying to finish up my android app and am running into a design issue. I had the UI set up the way that I wanted but am now wanting to change it to prevent any accidental clicks on my admob ad. I have a spinner dropdown showing as I'd prefer however the dropdown covers the whole screen and trying to select something at the bottom of this list might lead to accidental clicks of the ad. I'm hoping there is some secret way to limit the height of this dropdown that I have not been able to locate as of yet. Should I not be lucky enough for a shortcut to exist could someone please point me to a tutorial on how to accomplish this (preferably one that explains it and doesn't just tell you to copy and paste code). Thanks in advance for your help.

To make it easier to understand I created a spinner using an array adapter. The array has 30 variables in it. I want it to show at most 8-10 items and keep it above the admob ad. This is what I am wanting to accomplish essentially.

2 Answers

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

There does not appear to be an easy answer for this. I did a little research and tried a few things out. Your best bet for this is to create your own custom Spinner class where you can explicitly control the height, or perhaps use a Dialog instead and set the height of the Dialog. Hope this helps!

I was afraid of that. You wouldn't by chance know of a decent tutorial on how to create a custom Spinner class that uses the dropdown instead of a dialog would you? Everything I have found was for a dialog which I'm trying to avoid using due to simple design preference but looks like I might have to change that soon.