Get the value of the option chosen in Spinner

advertisements

I want to get value of choosed option in Spinner. I know, I can get this from setOnItemSelectedListener, but I don't want to use this. I have this:

String spinner1odp  = spinnerSubject.getSelectedItem().toString();

But result of this code is: [email protected] I want to get String, not something like that :/


I think you are popping up Spinner from database. So considering that you will have to get the selected index first and fetch the required data from the Cursor:

Code Snippet :

int position = mySpinner.getSelectedItemPosition();
Cursor cursor = (Cursor) myAdapter.getItem(position);
String myText = cursor.getString(cursor.getColumnIndex(KEY_NAME));

Further Reference : Android Spinner Selected Item