Reputation: 22637
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,
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,
Any ideas?
Upvotes: 2
Views: 2120
Reputation: 575
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.
Upvotes: 0
Reputation: 19149
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.
Upvotes: 1
Reputation: 10204
CheckedTextView
extends TextView
, which has inputType, maxLines, minLines
attributes.
Try applying android:inputType="textMultiline"
attribute to your CheckedTextView
, that should help.
Upvotes: 0