3

I'm not able to force AutoCompleteTextView drop down elements to wrap text in three or more lines.

As you can see:

drop-down before selection

drop-down after selection

The text in the first image (drop-down element) disappears, but I wont it to wrap into more lines.

Edited: This is my xml code for the dropdown item

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/text1"
    style="?android:attr/dropDownItemStyle"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:singleLine="false"
    android:lines="4"
    android:minLines="4"
    android:textSize="10sp"/>

How can I do this?

wildnove
  • 2,185
  • 2
  • 24
  • 32

2 Answers2

1

Solved! My layout dropdown_multiline_item.xml code become:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <TextView
        android:id="@+id/textContainer"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:lines="3"
        android:gravity="center_vertical"
        android:padding="5dp"
        android:textColor="#000"
        android:textSize="10sp" />

</LinearLayout>

The secret was on the two methods (into the adapter):

[...]

@Override
public void bindView(View view, Context context, Cursor cursor) {
    final String text = convertToString(cursor);
    ((TextView) view.findViewById(R.id.textContainer)).setText(text);
}

@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
    final LayoutInflater inflater = LayoutInflater.from(context);
    final View view = inflater.inflate(R.layout.dropdown_multiline_item, parent, false);
    return view;
}

[...]

Hope this will help someone

wildnove
  • 2,185
  • 2
  • 24
  • 32
0

Define a TextView as an XML layout with all the properties you need to make it look right (lines, ellipsize, maxLines, minLines, etc). The use the android:completionHintView attribute to set the dropdown to show the textview you defined.

toadzky
  • 3,806
  • 1
  • 15
  • 26