Get spinner selected items text?
Spinner spinner = (Spinner)findViewById(R.id.spinner); String text = spinner.getSelectedItem().toString();
Spinner spinner = (Spinner)findViewById(R.id.spinner); String text = spinner.getSelectedItem().toString();
The use of Runnables is completely incorrect. Use setSelection(position, false); in the initial selection before setOnItemSelectedListener(listener) This way you set your selection with no animation which causes the on item selected listener to be called. But the listener is null so nothing is run. Then your listener is assigned. So follow this exact sequence: Spinner … Read more
Some of the previous answers are not correct. They work for other widgets and views, but the documentation for the Spinner widget clearly states: A spinner does not support item click events. Calling this method will raise an exception. Better use OnItemSelectedListener() instead: spinner.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, … Read more
What you can do is decorate your SpinnerAdapter with one that presents a ‘Select Option…’ View initially for the Spinner to display with nothing selected. Here is a working example tested for Android 2.3, and 4.0 (it uses nothing in the compatibility library, so it should be fine for awhile) Since it’s a decorator, it … Read more