0

I am trying to get the selected item from a spinner, I want to then store this item into an array but at the moment I am just wondering how I can get the current selected item. Below is my current spinner code I have many spinners within the class.

Spinner session = (Spinner) findViewById(R.id.spinnerSession);
    ArrayAdapter<CharSequence> adapterSession = ArrayAdapter.createFromResource(
            this, R.array.session_array, android.R.layout.simple_spinner_item);
    adapterSession.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    session.setAdapter(adapterSession);

this spinner binds to an array defined within my strings file. So all I want it to get the item selected by the user.

thanks

mitchnufc
  • 309
  • 2
  • 3
  • 13

1 Answers1

0
public class MyOnItemSelectedListener implements OnItemSelectedListener {

    public void onItemSelected(AdapterView<?> parent,
        View view, int pos, long id) {
      Toast.makeText(parent.getContext(), "The planet is " +
          parent.getItemAtPosition(pos).toString(), Toast.LENGTH_LONG).show();
    }

    public void onNothingSelected(AdapterView parent) {
      // Do nothing.
    }
}

This is straight from the developer docs at: http://developer.android.com/resources/tutorials/views/hello-spinner.html

Basically you need to implement an onItemSelectedListener for the spinner.

Kevin
  • 532
  • 2
  • 7