Android Custom Layout for AutoCompleteTextView

I might be missing something simple, but I have an AutoCompleteTextView that contains very long elements. When one is clicked, it correctly displays the text in the EditText and spans it across multiple lines.

However, I want it to be on multiple lines in a popup so that users can see which item they select.

Here is my custom layout:

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:ellipsize="none"
    android:maxLines="100"
    android:scrollHorizontally="false" />

Here is my array and adapter initialization:

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                R.layout.dropdown_item_wrap_line,
                getResources().getStringArray(R.array.building_descriptions));

mBuildingDesc.setAdapter(adapter);
+5
source share
1 answer

I assume yours is AutoCompleteTextViewlimited singleLine, so using the default custom layout TextViewshould work neatly.

Layout custom_item.xml, ...

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <TextView 
        android:id="@+id/autoCompleteItem"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="5dp"
        android:textSize="14sp"    
        />

</LinearLayout>

AutoCompleteTextView

AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.autocomplete);
ArrayAdapter<String> adapter  = new ArrayAdapter<String>(this, R.layout.custom_item, R.id.autoCompleteItem, StringArray);
textView.setAdapter(adapter);
+9

All Articles