"If the "such" item is selected from spinner1, then "tal2" item from spinner2 is selected" how to do an if in that?

Asked

Viewed 747 times

-1

public void Spinner1() {
    Spinner spinner1 = (Spinner) findViewById(R.id.spinner1);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.curso_array, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner1.setAdapter(adapter);

}

public void Spinner2() {
    Spinner spinner2 = (Spinner) findViewById(R.id.spinner2);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.turma_array, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner2.setAdapter(adapter);

}

public void Spinner3() {
    Spinner spinner3 = (Spinner) findViewById(R.id.spinner3);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.periodo_array, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner3.setAdapter(adapter);

    if ("Redes de Computadores".equals(R.array.curso_array)) {
        ;
    }
}
  • 1

    Could explain your problem better?

  • So, I’m making a small form in my android app, but I’m having trouble in the part of Spinner. In this form there are three Spinners, being that it is Course, another one is Period and finally Class. The condition is: If the Course "Networks" item is selected, the Class "Afternoon" item is automatically selected. In both spinners I am using array. I hope I have explained! : D

  • You explained the condition for the Networks course, but what is the general logic Voce uses to determine what the second and third spinner should show based on what was chosen in the first spinner?

1 answer

2


When you set the spinner, put this code together to define a System that runs every time the selection changes.

    spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
    @Override
    public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
        // Aqui você checa se a nova seleção é o curso de redes.
        if (id == ID_DO_CURSO_REDES){
            // se for, definimos a seleção do spinner2 (periodo) para tarde.
            final spinner2 = (Spinner) findViewById(R.id.spinner2);
            spinner2.setSelection(ID_DO_PERIODO_TARDE);
        }
    }
    });

Browser other questions tagged

You are not signed in. Login or sign up in order to post.