2

I have a Spinner where the text both inside the spinner and the choices when the spinner is expanded (drop down view) can be quite long depending on the locale. i set a custom view for both the spinner view and the drop down view that should allow the text lines to wrap,

<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
    style="?android:attr/spinnerDropDownItemStyle"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ellipsize="none"
    android:minHeight="?android:attr/listPreferredItemHeight"
    android:singleLine="false" />

and in the code,

    spinnerPermission = (Spinner) layout.findViewById(R.id.permission_spinner);
    ArrayAdapter<CharSequence> permissionAdapter = ArrayAdapter.createFromResource(getActivity(), R.array.add_share_dialog_permissions,
        R.layout.multiline_spinner_dropdown_item);
    permissionAdapter.setDropDownViewResource(R.layout.multiline_spinner_dropdown_item);
    spinnerPermission.setAdapter(permissionAdapter);

this works fine in android 2, but in android 4, the text in the drop down view still won't wrap,

enter image description here

although it's not clear from the image, the text in the spinner view does wrap correctly. I can't tell for sure, but it seems like the container around the drop down views is not constrained by the screen and expands off the screen to the right. That would prevent the text from wrapping, because as far as the TextView is concerned, there's plenty of space.

Here is the spinner's popup view in hierarchy viewer,

enter image description here

Any ideas?

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Jeffrey Blattman
  • 22,176
  • 9
  • 79
  • 134
  • sorry, i don't understand what you mean. is that a suggestion? – Jeffrey Blattman Nov 14 '12 at 17:25
  • try setting the `layout_width` to an explicit value instead of `match_parent` for the dropdown view. – toadzky Nov 14 '12 at 17:27
  • i'm not sure that's a reasonable approach, considering all of the possible screen sizes and orientations. – Jeffrey Blattman Nov 14 '12 at 17:28
  • You could try examining your open `Spinner` in Hierarchy View and see if that tells you anything, such as confirming your "expands off the screen to the right" theory (which sounds plausible). I haven't tried viewing an open `Spinner` in Hierarchy View, so while I hope it'll work, it's possible that for some reason that is not possible. – CommonsWare Nov 14 '12 at 17:44
  • nah, german language is always so long, that is breaks boxes (design) – petey Nov 14 '12 at 17:50
  • @CommonsWare i can see it in hierarchy viewer. i don't see any evidence that it expands off the screen though. looking at the "bounds", it seems to end at the screen width (720). i'll attach this to the post. – Jeffrey Blattman Nov 14 '12 at 18:07
  • @toadzky setting an explicitly width just truncates the text and does not cause it to wrap. surprising. – Jeffrey Blattman Nov 14 '12 at 22:14
  • I recently created a question with the same topic that already got some upvotes but no solution yet: http://stackoverflow.com/q/14139106/1018177 – Matthias Robbers Jan 07 '13 at 21:30

3 Answers3

1

I have solved this by custom layout where I have TextView inside LinearLayout. Both TextView and LinearLayout have fixed width 200dp. Then it wraps the text correctly both on Android 2.3 and 4.0.

David Vávra
  • 18,446
  • 7
  • 48
  • 56
  • 1
    yes, that works, but i don't want to fix the width. if i do that, i have to consider the proper width against all sorts of different screens and orientations. – Jeffrey Blattman Jan 07 '13 at 19:54
0

CheckedTextView extends TextView, which has inputType, maxLines, minLines attributes. Try applying android:inputType="textMultiline" attribute to your CheckedTextView, that should help.

Andrii Chernenko
  • 9,873
  • 7
  • 71
  • 89
0

Create custom layout, first Goto res folder->create New XML Layout file eg: simple_spinner_layout.xml

link:http://justpaste.it/edit/2866098/aab2f5f3

Its work for me. Plz vote for this answer if u have satisfied.

Sakthivel Appavu
  • 565
  • 5
  • 24