Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I haven't found an easy and clean solution yet, only this workaround using custom adapters and a custom item class:</p> <p>First, we need a class for the spinner item content:</p> <pre><code>class SpinnerItem { private final String text; private final boolean isHint; public SpinnerItem(String strItem, boolean flag) { this.isHint = flag; this.text = strItem; } public String getItemString() { return text; } public boolean isHint() { return isHint; } } </code></pre> <p>Then our adapter class:</p> <pre><code>class MySpinnerAdapter extends ArrayAdapter&lt;SpinnerItem&gt; { public MySpinnerAdapter(Context context, int resource, List&lt;SpinnerItem&gt; objects) { super(context, resource, objects); } @Override public int getCount() { return super.getCount() - 1; // This makes the trick: do not show last item } @Override public SpinnerItem getItem(int position) { return super.getItem(position); } @Override public long getItemId(int position) { return super.getItemId(position); } } </code></pre> <p>Finally we use the workaround like this:</p> <pre><code>ArrayList&lt;SpinnerItem&gt; items = new ArrayList&lt;SpinnerItem&gt;(); items.add(new SpinnerItem("Item 1", false)); items.add(new SpinnerItem("Item 2", false)); items.add(new SpinnerItem("HINT", true)); // Last item MySpinnerAdapter adapter = new MySpinnerAdapter(this, android.R.layout.simple_spinner_item, items); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); spinner.setSelection(items.size() - 1); </code></pre> <p>Then you can use the flag from the SpinnerItem class to set text color for that item or whatever.</p>
    singulars
    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. 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