askIT

Android Get selected spinner item

A spinner is the same as a select list. An example is a select list where we define if we want to use metric or imperial units.

Example of a spinner:

Example 1 - Get spinner value text

Spinner spinner = (Spinner)findViewById(R.id.spinner);
String text = spinner.getSelectedItem().toString();

.. and for mesurment spinner:

Spinner spinnerMesurment = (Spinner)findViewById(R.id.spinnerMesurment);
String stringMesurment = spinnerMesurment.getSelectedItem().toString();

Example 2 - Get spinner value id

Spinner spinner = (Spinner)findViewById(R.id.spinner);
int position = spinner.getSelectedItemPosition();

.. and for mesurment spinner:

Spinner spinnerMesurment = (Spinner)findViewById(R.id.spinnerMesurment);
int intMesurment = spinnerMesurment.getSelectedItemPosition();

Add comment

avatar_blank_60.png

Comment:

Name:

Email:

Comments

No comments yet. You can be the first one to comment. Just write your comment in the form and click on the submit button.