In a Spinner-type component, how do I fix it with a data that comes from a webservice?

0

Am I doing it this way would be the correct one? The problem is that it is not working as expected follows code:

Here I take the data that comes from a list and the other screen and save it in situation:

         situacao = bundle.getString("situacao");

Here I want to set the Spinner component with this option:

        spinnerSituacao.setSelection(Integer.parseInt(situacao));

But what's wrong is not working right? situation is a String that can be "1" or "2".

I've added the list to be displayed in Spinner this way:

List<String> listaSituacao = new ArrayList<String>();
    listaSituacao.add("Ativo");
    listaSituacao.add("Desativado");

    ArrayAdapter<String> adapterSituacao = new ArrayAdapter<String>(context, android.R.layout.simple_spinner_dropdown_item, listaSituacao);

And to get its value this way:

 spinnerSituacao.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            Situacao = String.valueOf(position + 1);

        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });
    
asked by anonymous 14.12.2016 / 19:41

0 answers