Hello, I have a code that has two spinners and if we select an option in a spinner in the other this option ceases to exist, what I did was: Whenever you click on the spinner it does clear and adds all and then removes what is selected in the other so that it can not be selected in both! But when I select something in one, it goes into an infinite loop, as if it were always doing the OnItemSelected method does anyone know why? Here is the code:
disciplinasFirst.add("Biologia e Geologia");
disciplinasFirst.add("Física e Química A");
disciplinasFirst.add("Geometria Descritiva A");
disciplinasFirst.add("Química");
final ArrayAdapter<String> adapterDitsciplinasFirst = new ArrayAdapter<String>(ChoseDisciplinas2.this, R.layout.spinner_item_beggin, disciplinasFirst);
adapterDitsciplinasFirst.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
SpinnerFirst.setAdapter(
new NothingSelectedSpinnerAdapter(
adapterDitsciplinasFirst,
R.layout.contact_spinner_row_nothing_selected,
// R.layout.contact_spinner_nothing_selected_dropdown, // Optional
this));
disciplinasSecond.add("Biologia e Geologia");
disciplinasSecond.add("Física e Química A");
disciplinasSecond.add("Geometria Descritiva A");
disciplinasSecond.add("Química");
final ArrayAdapter<String> adapterDisciplinasSecond = new ArrayAdapter<String>(ChoseDisciplinas2.this, R.layout.spinner_item_beggin, disciplinasSecond);
adapterDisciplinasSecond.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
SpinnerSecond.setAdapter(
new NothingSelectedSpinnerAdapter(
adapterDisciplinasSecond,
R.layout.contact_spinner_row_nothing_selected,
// R.layout.contact_spinner_nothing_selected_dropdown, // Optional
this));
SpinnerSecond.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if (SpinnerFirst.getSelectedItem() != null) {
disciplinasSecond.clear();
disciplinasSecond.add("Biologia e Geologia");
disciplinasSecond.add("Física e Química A");
disciplinasSecond.add("Geometria Descritiva A");
disciplinasSecond.add("Química");
disciplinasSecond.remove(SpinnerFirst.getSelectedItem().toString());
final ArrayAdapter<String> adapterDisciplinasSecond = new ArrayAdapter<String>(ChoseDisciplinas2.this, R.layout.spinner_item_beggin, disciplinasSecond);
SpinnerSecond.setAdapter(adapterDisciplinasSecond);
Log.d(Tag,"fui selecionado2");
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
SpinnerFirst.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if(SpinnerSecond.getSelectedItem()!=null){
disciplinasFirst.clear();
disciplinasFirst.add("Biologia e Geologia");
disciplinasFirst.add("Física e Química A");
disciplinasFirst.add("Geometria Descritiva A");
disciplinasFirst.add("Química");
disciplinasFirst.remove(SpinnerSecond.getSelectedItem().toString());
final ArrayAdapter<String> adapterDitsciplinasFirst = new ArrayAdapter<String>(ChoseDisciplinas2.this, R.layout.spinner_item_beggin, disciplinasFirst);
SpinnerFirst.setAdapter(adapterDitsciplinasFirst);
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
Disciplines First and Disciplines Second are the content of the Spinners in this case Spinner First and Spinner Second respectively.
Thank you and a good evening or good afternoon to the Brazilians!