How to manage the height of android spinner items?

rushinge picture rushinge · Jun 13, 2010 · Viewed 22.8k times · Source

I have an android spinner that's populated by a list of strings using an ArrayAdapter and it operates fine, however because of the way the spinner is displayed I'm running into a display height problem with the list items.

At first glance, it would seem that the ArrayAdapter can use a single layout for displaying options which leads to the problem I'm having. When displaying the current item in the spinner (when the user is not selecting a new item from the list) the spinner pads the text so that the spinner is a reasonable size for clicking on. However, when the user taps on it and brings up the list to select a new item, the list items presented are way too small height-wise. If I use an item layout that presents the list items at a reasonable height, then the spinner itself becomes exorbitantly huge due to its own padding of the list item.

Any ideas on how I can manage the height of these two item display modes so that effectively they display with the same height value instead of the spinner height being larger than the list item display height?

Answer

Pentium10 picture Pentium10 · Jun 13, 2010

I've run into this issue myself a while ago, and it turned out that I need to use different layouts for dropdown and display

I have this code:

adapter = new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, cGroups,
                new String[] {
                        "name", "_id"
                }, new int[] {
                    android.R.id.text1
                });
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);