Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I figured out that to make this work you have to override the getDropDownView when setting up the ArrayAdapter in the main activity. </p> <pre><code>public class main extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); PatchedSpinner pSpinner = (PatchedSpinner) findViewById(R.id.spinner2); ArrayList&lt;String&gt; testarray = new ArrayList&lt;String&gt;(); testarray.add("item0"); testarray.add("item1"); testarray.add("item2"); testarray.add("item3"); ArrayAdapter&lt;String&gt; spinnerAdapter = new ArrayAdapter&lt;String&gt;(this,android.R.layout.simple_spinner_dropdown_item, testarray) { @Override public boolean isEnabled(int position) { return position != 1; } @Override public boolean areAllItemsEnabled() { return false; } @Override public View getDropDownView(int position, View convertView, ViewGroup parent){ View v = convertView; if (v == null) { Context mContext = this.getContext(); LayoutInflater vi = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); v = vi.inflate(R.layout.row, null); } TextView tv = (TextView) v.findViewById(R.id.spinnerTarget); tv.setText(testarray.get(position)); switch (position) { case 0: tv.setTextColor(Color.RED); break; case 1: tv.setTextColor(Color.BLUE); break; default: tv.setTextColor(Color.BLACK); break; } return v; } }; pSpinner.setAdapter(spinnerAdapter); } </code></pre> <p>The layout that is being inflated is a custom layout called row.xml. it is used to set the display for the dropdown view.</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/spinnerTarget" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textSize="14pt" /&gt; </code></pre>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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