Search code examples
androidpositionsetspinner

How change to the next position in a spinner of android?


I have a spinner with 3 options. The first option shows up with the method onCreate. When the first option is selected, in an EditText I write something, and click in a button to save it. Well, my question is if I can change the spinner to the next option when I press the button.


Solution

  • set an OnClickListener to your Button. In the onClick method set the selection of the spinner to the current selected value and add "1"

     myButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(final View v) {
                mySpinner.setSelection(mySpinner.getSelectedItemPosition()+1);
    

    }