Get spinner selected items text?

How to get spinner selected item's text?

I have to get the text on the item selected in my spinner when i click on the save button. i need the text not the Index.


Solution 1:

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

Solution 2:

TextView textView = (TextView)mySpinner.getSelectedView();
String result = textView.getText().toString();

Solution 3:

You have to use the index and the Adapter to find out the text you have

See this example of Spinner

public class MyOnItemSelectedListener implements OnItemSelectedListener {

    public void onItemSelected(AdapterView<?> parent,
        View view, int pos, long id) {
      Toast.makeText(parent.getContext()), "The planet is " +
          parent.getItemAtPosition(pos).toString(), Toast.LENGTH_LONG).show();
    }

    public void onNothingSelected(AdapterView parent) {
      // Do nothing.
    }
}