SpinnerAdapter showing terribly small items on Android 2.2

3,829 views
Skip to first unread message

Håkon Nilsen

unread,
Mar 9, 2012, 5:20:34 PM3/9/12
to actionba...@googlegroups.com
I'm implementing ActionBarSherlock on an Android 4.0-app, so that it can be used for Android 2.x. However, there is this one issue that I can't figure out what to do with; I have a spinner for selecting geographical regions. The names can be quite long, and I'm afraid that has something to do with the result, but I've taken a screenshot for you so that you can see my problem.

I haven't found anything useful on Google yet, so I'm writing here. Thank you :-)
device-2012-03-09-231228.png

Håkon Nilsen

unread,
Mar 9, 2012, 5:23:45 PM3/9/12
to actionba...@googlegroups.com
Here is the code snippet by the way:

        ab.setDisplayShowTitleEnabled(false);
        ab.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
        ab.setDisplayHomeAsUpEnabled(true);

        SpinnerAdapter mSpinnerAdapter = ArrayAdapter.createFromResource(this, R.array.pref_regions,
                R.layout.sherlock_spinner_item); 
 
        ab.setListNavigationCallbacks(mSpinnerAdapter, mOnNavigationListener);
        ab.setSelectedNavigationItem(mRegionId); 

Håkon Nilsen

unread,
Mar 9, 2012, 5:27:15 PM3/9/12
to actionba...@googlegroups.com
And it's the same on the Galaxy Nexus. Just verified it how.

Håkon Nilsen

unread,
Mar 9, 2012, 5:58:44 PM3/9/12
to actionba...@googlegroups.com
I've made my own sherlock_spinner_item.xml that takes into account the text size and padding. It now looks better, but I'm guessing ActionBarSherlock should handle this out-of-the-box.

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@android:id/text1"
          style="?attr/spinnerItemStyle"
          android:singleLine="true"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:textSize="18dp"
          android:paddingTop="8dp"
          android:paddingBottom="8dp"
          android:paddingLeft="8dp"
          android:paddingRight="8dp"
          android:ellipsize="marquee" />

Jake Wharton

unread,
Mar 9, 2012, 6:32:36 PM3/9/12
to actionba...@googlegroups.com
You need to call setDropDownViewResource. You can find an example of this in the 'List Navigation' example of the demos sample app: https://github.com/JakeWharton/ActionBarSherlock/blob/master/samples/demos/src/com/actionbarsherlock/sample/demos/ListNavigation.java#L26

---
Jake Wharton
http://about.me/jakewharton


2012/3/9 Håkon Nilsen <hni...@gmail.com>

Håkon Nilsen

unread,
Mar 9, 2012, 7:24:33 PM3/9/12
to actionba...@googlegroups.com
Thank you for answering. I did what you said, here is the code now (no SpinnerAdapter any more):

    private void actionBarSetup() {
        ActionBar ab = getSupportActionBar(); 

        ab.setDisplayShowTitleEnabled(false);
        ab.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
        ab.setDisplayHomeAsUpEnabled(true); 

        Context context = ab.getThemedContext();
        ArrayAdapter<CharSequence> list = ArrayAdapter.createFromResource(context, R.array.pref_regions,
                R.layout.sherlock_spinner_item); 
 
        list.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item);
        ab.setListNavigationCallbacks(list, this);
        ab.setSelectedNavigationItem(mRegionId);
    }

But I get this error:
java.lang.RuntimeException: Binary XML file line #20: You must supply a layout_height attribute.

I don't really know where it comes from. This is on a Galaxy Nexus. On an old HTC Desire running Android 2.2, it runs fine now.


Best regards,
Håkon Nilsen

Håkon Nilsen

unread,
Mar 9, 2012, 8:04:11 PM3/9/12
to actionba...@googlegroups.com
A little update;

In sherlock_spinner_dropdown_item.xml that is in layout-v14 seems to be the problem. I changed this line:
     android:layout_height="?attr/dropdownListPreferredItemHeight"

With this line:
    android:layout_height="48dp"

That fixed it. I'm not sure why it can't resolve the attribute, but perhaps you know?

Jake Wharton

unread,
Mar 9, 2012, 8:08:03 PM3/9/12
to actionba...@googlegroups.com
What theme are you using?
2012/3/9 Håkon Nilsen <hni...@gmail.com>
A little update;

Håkon Nilsen

unread,
Mar 9, 2012, 8:26:12 PM3/9/12
to actionba...@googlegroups.com
I'm using my own theme that inherits from Theme.Sherlock. Like this:

    <style name="Theme.PollenTema" parent="Theme.Sherlock">
        <item name="vpiTabPageIndicatorStyle">@style/Widget.TabPageIndicator</item>
        <item name="vpiTabTextStyle">@style/Widget.TabPageIndicator.Text</item>
    </style>

--
Håkon Nilsen

Jake Wharton

unread,
Mar 9, 2012, 8:31:24 PM3/9/12
to actionba...@googlegroups.com

That should have access to that attribute with no problem. If you want to create a small reproducible test case and send it along feel free. I know it works on every theme using the included samples so I'm not sure what's going on in your case.

Håkon Nilsen

unread,
Mar 9, 2012, 8:33:45 PM3/9/12
to actionba...@googlegroups.com
Ok, I'll try my best to reproduce this in a new project.

Skip Mercier

unread,
Mar 10, 2012, 3:13:52 AM3/10/12
to actionba...@googlegroups.com
I'm having this exact same problem and was certain I was doing something wrong. I'm also using a few custom subthemes with parent Theme.Sherlock to vary the text size, but nothing specific to the ActionBar. Changing android:layout_height="?attr/dropdownListPreferredItemHeight" in sherlock_spinner_dropdown_item.xml that is in layout-v14 also fixed the problem.

Håkon Nilsen

unread,
Mar 10, 2012, 5:14:58 AM3/10/12
to actionba...@googlegroups.com
Are you using Eclipse or some other IDE?

I'm using IntelliJ IDEA exclusively, and I'm just wondering if this has something to do with some odd IDEA-way of doing stuff.

Håkon Nilsen

unread,
Mar 10, 2012, 5:42:47 AM3/10/12
to actionba...@googlegroups.com
Ok, I've managed to reproduce it in your own demos.

This is the addition I put int your AndroidManifest.xml:
        <activity
                android:name=".PollenListActivity"
                android:label="PollenListActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="com.actionbarsherlock.sample.demos.EXAMPLE" />
            </intent-filter>
        </activity>

I'm also attaching two javaclasses, one SherlockFragmentActitivy and one Fragment. I believe it's the fragments that are messing up here. This is basically code that's copied from my own.


Best regards,
Håkon Nilsen


PollenListActivity.java
PollenListFragment.java

Håkon Nilsen

unread,
Mar 13, 2012, 3:26:02 PM3/13/12
to actionba...@googlegroups.com
I'm still clueless on why this happens. I was just wondering if anyone else is experiencing the same issue, and if they have resolved it some other way. See my example code here: https://groups.google.com/d/msg/actionbarsherlock/aODtoH2aS-s/A2I55UU0WxAJ

(it goes into the ABS demo along with the other java files, and be sure to add the activity to the AndroidManifest.xml of the demo as well)

I'm guessing it's more of a fragment issue than theme issue, but I can't be sure.

Skip Mercier

unread,
Mar 13, 2012, 3:58:48 PM3/13/12
to actionba...@googlegroups.com
I'm using Eclipse.

Henrik Larsen

unread,
Sep 19, 2012, 3:50:44 PM9/19/12
to actionba...@googlegroups.com
Have been banging my head for a couple of hours with this error. 

I godt a error about unable to inflate xml-file because android:layout_height was unspecified without a clue as to what file was at fault. Turns out it was v14  sherlock_spinner_dropdown_item.xml. 

In my case i use HoloEverywhere in combination with ABS so i guess it is a sub theme that has missed this style which caused the bug. 

Fixed it by extending the Holo.Theme and then add the original code from the v14/styles:


layout-v14/styles.xml
 <style name="AppTheme" parent="@style/Holo.Theme.Sherlock.Light">
        <item name="dropdownListPreferredItemHeight">48dp</item>
    </style>

Would probably never have found this bug if it wasn't for this thread, so thanks :)

Dan Hughes

unread,
Apr 5, 2013, 6:34:18 PM4/5/13
to actionba...@googlegroups.com
Just came across this issue, fixed it by calling setTheme to a sherlock theme in onCreate

i.e:
setTheme(R.style.Theme_Sherlock_Light);

Bit of a late post but thought it might be useful to others

Ashok chakravarthi

unread,
Sep 3, 2014, 1:29:42 PM9/3/14
to actionba...@googlegroups.com
I have already set the Theme in Manifest xml file for the specific activity, then is this necessary to call it again, like you specified?  Is this Kinda workaround? 
Reply all
Reply to author
Forward
0 new messages