top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to get value form spinner in android studio?

+2 votes
522 views

I am using drop down menu (spinner) and I want know how to get value from drop down menu to a variable if user selects one?
Example : select city=Varanasi,Delhi,Chennai,Erode etc. and if user selects Chennai then store it to a java variable.

   String selectedCity;
   //after selecting from drop down menu
   selectedCity="Chennai";
posted Mar 3, 2016 by Shivam Kumar Pandey

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
Spinner mySpinner=(Spinner) findViewById(R.id.your_spinner);
String selectedCity = mySpinner.getSelectedItem().toString();

try this....
Vote up, if you find it helpful.

answer Mar 9, 2016 by Manoj Yadav
Similar Questions
+2 votes

How to send the 3 edittext values and 2 spinner values as a single message to particular number while clicking send button?

+2 votes

I have added a floating action button in my layout but using backgroundtilt, it doesn't change the color of background.

Here my code segment

   <android.support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/AddNewButton"
        android:background="@drawable/add"
        android:layout_margin="15dp"
        app:rippleColor="@android:color/white"
        app:fabSize="normal"
        android:clickable="true"
        app:layout_anchor="@+id/HeaderSection"
        app:layout_anchorGravity="bottom|right|end"/>
...