Note that there are some explanatory texts on larger screens.

plurals
  1. POChange spinner states dynamically
    primarykey
    data
    text
    <p>I am trying to change state style of a spinner programmatically.</p> <p>But when I press an item, all of them are changed! Before pressing everything's fine, the colors are good:</p> <p><img src="https://i.stack.imgur.com/wMd4B.png" alt="enter image description here"></p> <p>When pressing, all items become green: <img src="https://i.stack.imgur.com/9uYhL.png" alt="enter image description here"></p> <p>I did this in my custom adapter :</p> <pre><code>@Override public View getDropDownView(int position, View convertView, ViewGroup parent) { //getting the views and all the stuff StateListDrawable colorStateList = new StateListDrawable(); colorStateList.addState(new int[] {android.R.attr.state_focused, android.R.attr.state_pressed}, new ColorDrawable(Color.BLACK)); colorStateList.addState(new int[] {android.R.attr.state_focused }, new ColorDrawable(Color.BLUE)); colorStateList.addState(new int[] { android.R.attr.state_pressed}, new ColorDrawable(Color.GREEN)); colorStateList.addState(new int[] { }, new ColorDrawable(Color.YELLOW)); holder.container.setBackgroundDrawable(colorStateList); return convertView; } </code></pre> <p>Here is my custom dropdown layout </p> <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/spinner_container" android:layout_width="@dimen/icon_ligne_size" android:layout_height="@dimen/icon_ligne_size" android:layout_gravity="left" android:gravity="left" android:orientation="horizontal" &gt; &lt;TextView android:id="@+id/spinner_dir1" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="3" android:gravity="center_vertical" android:textAppearance="@android:style/TextAppearance.Medium" /&gt; &lt;ImageView android:id="@+id/spinner_arrow" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_gravity="left" android:layout_weight="1" /&gt; &lt;TextView android:id="@+id/spinner_dir2" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="3" android:gravity="center_vertical" android:textAppearance="@android:style/TextAppearance.Medium" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>(I know this is uggly but this is just for testing)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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