Alan Lai Alan Lai - 1 year ago 238
Android Question

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?

Answer Source

Try this thing.

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

Like this you can get value for different Spinners.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download