Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: Make AutoCompleteTextView dropdown wrap to 2 lines or more
    text
    copied!<p>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 have a custom list_item.xml, but only one line of text displays. The list_item.xml layout wraps to 2 lines if used with a spinner, but not with the AutoCompleteTextView.</p> <p>main.java</p> <pre><code>public class main extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.autocomplete_country); ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this, R.layout.list_item, COUNTRIES); textView.setAdapter(adapter); } static final String[] COUNTRIES = new String[] { "This is the first line that is too long and it needs to wrap content", "Albania", "Algeria", "American Samoa", "Andorra", "This is a second line that also needs to wrap its content", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium" }; } </code></pre> <p>main.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:padding="5dp"&gt; &lt;TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Country" /&gt; &lt;AutoCompleteTextView android:id="@+id/autocomplete_country" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="5dp"/&gt; &lt;/LinearLayout&gt; </code></pre> <p>list_item.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:padding="10dp" android:textSize="16sp" android:textColor="#000" &gt; &lt;/TextView&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload