Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I had this same problem and found a solution. </p> <p>I wanted the text to wrap in the initial display and in the dropdown view as well.</p> <p>The text was wrapping in the initial display and for the dropdown I had found another solution recommending the use a custom view of a linear layout with fixed width enclosing a textview. This made the dropdown of the spinner look correct, as well as that of the initial selection. However, this caused a major problem on older devices.</p> <p>The initial display would not refresh and the text took on a stacked look if I tried to select something else. and since it stacked downward adding a background didn't help. <img src="https://i.stack.imgur.com/XOqPC.png" alt="enter image description here"></p> <p>As it turns out adapters have a method called setDropDownViewResource() which allows you to set a different view for the dropdown than what is displayed in the spinner's initial selection. </p> <pre><code> import org.holoeverywhere.widget.Spinner; ArrayAdapter adapter1 = ArrayAdapter.createFromResource(this,R.array.array_of_strings,R.layout.simple_list_item_1); adapter1.setDropDownViewResource(R.layout.my_simple_list_item_1); spQ1.setAdapter(adapter1); </code></pre> <p>in this example the simple_list_item is the default view supplied by android and my_simple_list_item is</p> <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="300dp" android:layout_height="wrap_content" &gt; &lt;TextView android:id="@+id/android:text1" android:layout_width="wrap_content" android:layout_height="50dp" android:ellipsize="marquee" android:layout_gravity="center_vertical" android:singleLine="false"/&gt; &lt;/LinearLayout&gt; </code></pre> <p>Now the text wraps inside the dropdown view of the spinner AND in the spinners displayed selection. </p>
 

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