How to change the Spinner font color?

I’m going to use Spinner project sample from Android SDK for next code examples. Code: First, you need to create you custom adapter which will intercept the creation of views in drop down list: static class CustomArrayAdapter<T> extends ArrayAdapter<T> { public CustomArrayAdapter(Context ctx, T [] objects) { super(ctx, android.R.layout.simple_spinner_item, objects); } //other constructors @Override public … Read more

How to dynamically populate Android spinner with text + image

Try this.. public class SpinnerAdapter extends ArrayAdapter<String> { private Context ctx; private String[] contentArray; private Integer[] imageArray; public SpinnerAdapter(Context context, int resource, String[] objects, Integer[] imageArray) { super(context, R.layout.spinner_value_layout, R.id.spinnerTextView, objects); this.ctx = context; this.contentArray = objects; this.imageArray = imageArray; } @Override public View getDropDownView(int position, View convertView,ViewGroup parent) { return getCustomView(position, convertView, parent); } … Read more

Creating a setError() for the Spinner

Similar to @Gábor’s solution, but I didn’t need to create my own adapter. I just call the following code in my validate function (i.e. on submit button clicked) TextView errorText = (TextView)mySpinner.getSelectedView(); errorText.setError(“anything here, just to add the icon”); errorText.setTextColor(Color.RED);//just to highlight that this is an error errorText.setText(“my actual error text”);//changes the selected item text … Read more

How to create android spinner without down triangle on the right side of the widget

This is quite an old question, but I think still relevant, so here’s my answer: Simplest Method lencinhaus answer is correct. It works, but it can be done in an even simpler way: Just add another background to it. The example below uses the standard Button background for a more homogeneous look-and-feel: <Spinner android:id=”@+id/my_spinner” android:layout_width=”wrap_content” … Read more

How to add items to a spinner in Android?

XML file: <Spinner android:id=”@+id/Spinner01″ android:layout_width=”wrap_content” android:layout_height=”wrap_content”/> Java file: public class SpinnerExample extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); String[] arraySpinner = new String[] { “1”, “2”, “3”, “4”, “5”, “6”, “7” }; Spinner s = (Spinner) findViewById(R.id.Spinner01); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, arraySpinner); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); s.setAdapter(adapter); } } See spinner example.

How to hide one item in an Android Spinner

To hide an arbitrary item or more than one item I think that you can implement your own adapter and set the index (or array list of indexes) that you want to hide. public class CustomAdapter extends ArrayAdapter<String> { private int hidingItemIndex; public CustomAdapter(Context context, int textViewResourceId, String[] objects, int hidingItemIndex) { super(context, textViewResourceId, objects); … Read more