[Solved] How to get Spinner selected item value to string?

I have 5 Spinners. In order to make it summary to this.

This is Spinner in xml

            android:prompt="@string/interestedprompt" />

This is Spinner in Java

submitbtn.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
interested.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                        public void onItemSelected(
                                AdapterView<?> adapterView, View view,
                                int i, long l) {
                            interesting = interested.getItemAtPosition(i).toString();

                        public void onNothingSelected(
                                AdapterView<?> adapterView) {


Explanation here:

The page got a button. This button will read the data from spinner when pressed. I checked the output with this


It gave me nothing not even null.

How to retrieve the value and to string it?

Enquirer: Alan Lai


Solution #1:

Try this:

String text = mySpinner.getSelectedItem().toString();

Like this you can get value for different Spinners.

Respondent: Bhavin

Solution #2:

String Text = mySpinner.getSelectedItem().toString();


mySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
        Object item = parent.getItemAtPosition(position);
    public void onNothingSelected(AdapterView<?> parent) {
Respondent: santoshpatmca

Solution #3:

You can get the selected item from Spinner by using,

Respondent: Lalit Poptani

Solution #4:

If your Spinner was populated by SQLite cursor, then the solution is:

Spinner mySpin = (Spinner) findViewById(;
mySpin.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {  
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
           SQLiteCursor item = (SQLiteCursor) parent.getItemAtPosition(position);
           String value = String.valueOf(item.getString(0));
           Toast.makeText(getApplicationContext(), "The option is:" + value , Toast.LENGTH_SHORT).show(); 

PS: In item.getString(0) -> 0 is the index of column on cursor that you want to get.

Respondent: Mduarth

Solution #5:

try this

 final Spinner cardStatusSpinner1 = (Spinner) findViewById(;
    String cardStatusString;
    cardStatusSpinner1.setOnItemSelectedListener(new OnItemSelectedListener() {

        public void onItemSelected(AdapterView<?> parent,
                View view, int pos, long id) {
            cardStatusString = parent.getItemAtPosition(pos).toString();

        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub


 final Button saveBtn = (Button) findViewById(;
    saveBtn .setOnClickListener(new OnClickListener() {

        public void onClick(View arg0) {
            // TODO Auto-generated method stub

            System.out.println("Selected cardStatusString : " + cardStatusString ); //this will print the result
Respondent: sush

Solution #6:

Get the selected item with Kotlin:

Respondent: Westy92

Solution #7:

In addition to the suggested,

String Text = mySpinner.getSelectedItem().toString();

You can do,

String Text = String.valueOf(mySpinner.getSelectedItem());
Respondent: Max

Solution #8:

When you choose any value from spinner, then you get selected value,

Respondent: Andy

Solution #9:

I think you want the selected item of the spinner when button is clicked..

Try getSelectedItem():

Respondent: ngesh

Solution #10:

The best way to do this is :-

String selectedItem = spinner.getSelectedItem().toString();

you can refer the docs here : Spinners

Respondent: Deepak Vardhan

Solution #11:

try this

sp1 = String.valueOf(spinner.getSelectedItem());
Respondent: Thasreef Mogral

Solution #12:

Since the latest language for Android Development is Kotlin. Here is, how we do it in Kotlin using Anonymous object.

spinnerName?.onItemSelectedListener = object : AdapterView.OnItemSelectedListener{
    override fun onNothingSelected(parent: AdapterView<*>?) {
       println("Nothing Selected")

    override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
       val selectedString = yourList[position]

Respondent: Hanny

Solution #13:

By implementing the SpinnerAdapter for your adapter object i use interested.getItem(i).toString()

Respondent: GedankenNebel

Solution #14:

    spinnerType = (AppCompatSpinner) findViewById(;
    spinnerType.setPrompt("Select Type");

    spinnerType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            TypeItem clickedItem = (TypeItem) parent.getItemAtPosition(position);
            String TypeName = clickedItem.getTypeName();
            Toast.makeText(AddAccount.this, TypeName + " selected", Toast.LENGTH_SHORT).show();

        public void onNothingSelected(AdapterView<?> parent) {

Respondent: Malith Ileperuma

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Most Popular

To Top
India and Pakistan’s steroid-soaked rhetoric over Kashmir will come back to haunt them both clenbuterol australia bossier man pleads guilty for leadership role in anabolic steriod distribution conspiracy