10

I recently just implemented the holo theme into my android app. After doing this, any spinner that I have, where the drop down item is multiple lines long, will not wrap the text to multiple lines. Each drop down item is kept all on one line and truncated to a certain length.

Here is my xml for the drop down resource for the spinner

<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@android:id/text1"
style="?android:attr/spinnerDropDownItemStyle"
android:singleLine="false"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="none" />

This works on older versions of android before ICS and the holo theme.

Has anyone else encountered this issue?

Swati Garg
  • 995
  • 1
  • 10
  • 21
Jeff
  • 101
  • 1
  • 3
  • I have the same problem. I have multiline spinners except in version 4.0.4. Sure would like to find a workaround for this bug. – Ted Betz Nov 14 '12 at 04:16
  • See this answer: http://stackoverflow.com/questions/14139106/spinner-does-not-wrap-text-is-this-an-android-bug/14392369#14392369 – Gunnar Karlsson Jan 18 '13 at 04:28

1 Answers1

0

As i had mentioned in : Spinner does not wrap text -- is this an Android bug?

I think there is a bug on android. You could try this. Remove the spaces from the text and then display it would work fine. If the length of the textview is < that of the string, it ignores all the characters after the space. For a work-around you could try this :

add a file to res/layout folder named multiline_spinner_dropdown_item.xml with the sample code:

<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/sample_text"
style="?android:attr/spinnerDropDownItemStyle"
android:singleLine="false"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:ellipsize="marquee" />

and when you are creating the spinner create it from this layout.

Something like :

ArrayAdapter.createFromResource(this, items, R.layout.multiline_spinner_dropdown_item);

Basically, copy the android.R.layout.simple_spinner_dropdown_item layout into the project and modify the layout by setting singleLine attribute to false in CheckedTextView.

Community
  • 1
  • 1
lokoko
  • 5,785
  • 5
  • 35
  • 68