GetSelectedItemPosition () of the counter always returns 0

I am trying to have a warning window display the selected item on the counter, and I will need a position later in the code. I tested, and spiAli.getSelectedItemPosition () returns 0 before switching. Here is my line:

private static final String[] listaAlimentos =
        {"Arroz","Feijão","Bife"};
ArrayAdapter<String> alistaAlimentos;    

And a function that does not work:

 butFinalizar.setOnClickListener(new View.OnClickListener() {
        public void onClick(View arg0) {
            String escolhaAlimento = null;
            String escolhaExercicio = null;

            if (cbAlimento.isChecked()) {
                int selected = spiAli.getSelectedItemPosition();
                switch (selected) {
                    case (0):
                        escolhaAlimento = "Arroz";
                        break;
                    case (1):
                        escolhaAlimento = "Feijão";
                        break;
                    case (2):
                        escolhaAlimento = "Bife";
                        break;
                }
                AlertDialog.Builder dialogo = new
                        AlertDialog.Builder(MainActivity.this);
                dialogo.setTitle("Aviso");
                dialogo.setMessage("Escolha:" + escolhaAlimento);
                dialogo.setNeutralButton("OK", null);
                dialogo.show();
            }

        }
    });
+4
source share

All Articles