Skip to content Skip to sidebar Skip to footer

Android: Make Autocompletetextview Dropdown Wrap To 2 Lines Or More

I am writing an Android app that uses an AutoCompleteTextView just like the API example. The problem is that my text is too long and needs to wrap when the dropdown occurs. I hav

Solution 1:

Wrap the TextView in a layout and use that for your ArrayAdapter

<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent" ><TextViewandroid:id="@+id/item"android:layout_width="fill_parent"android:layout_height="wrap_content"android:padding="10dp"android:textSize="16sp"android:textColor="#000"    
        /></LinearLayout>

And the new calls for the ArrayAdapter:

AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.autocomplete_country);
    ArrayAdapter<String> adapter  = newArrayAdapter<String>(getActivity(), R.layout.list_item, R.id.item, COUNTRIES);
    textView.setAdapter(adapter);

Solution 2:

easy way : adapter = new ArrayAdapter(getApplicationContext(), android.R.layout.two_line_list_item,android.R.id.text1,....);

android.R.layout.two_line_list_item this is easy change.

Post a Comment for "Android: Make Autocompletetextview Dropdown Wrap To 2 Lines Or More"