How to get the selected spinner item to a string?
Asked Answered
O

2

5

I'm very confused, I can select an item from spinner and display it in a pop up message. I have this,

btnSubmitRequest.Click += (sender, e) =>
        {
            spinnerJobTypes.ItemSelected += new EventHandler<AdapterView.ItemSelectedEventArgs>(spinnerJobTypes_ItemSelected);
        }


private void spinnerJobTypes_ItemSelected(object sender, AdapterView.ItemSelectedEventArgs e)
    {
        Spinner spinner = (Spinner)sender;

        string toast = string.Format("{0}", spinner.GetItemAtPosition(e.Position));
        Toast.MakeText(this, toast, ToastLength.Long).Show();
    }

How can I get the response from spinnerJobTypes_ItemSelected to a string so that I can submit it into the database?

Any help is greatly appreciated

Obligatory answered 25/4, 2017 at 15:13 Comment(0)
C
7

@Jeff.H is right, but you need the answer in C#. So, you have to do something like this (I tried it):

 Spinner spinner = (Spinner)sender;
 string selectedItem = spinner.SelectedItem.ToString();

Hope this help you.

Chickadee answered 25/4, 2017 at 15:57 Comment(1)
Thank you so much. Works perfectly :)Obligatory
M
2

You could try something like this

Spinner spinner = (Spinner)findViewById(R.id.spinner); 
String text = spinner.getSelectedItem().toString();
Mostly answered 25/4, 2017 at 15:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.