Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the selected spinner item to a string?

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

like image 419
KMR Avatar asked Apr 25 '17 15:04

KMR


2 Answers

@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.

like image 168
Luis E. Vega Avatar answered Oct 04 '22 18:10

Luis E. Vega


You could try something like this

Spinner spinner = (Spinner)findViewById(R.id.spinner); 
String text = spinner.getSelectedItem().toString();
like image 29
Jeff.H Avatar answered Oct 04 '22 19:10

Jeff.H