0
Hello, I have a code that has two spinners and that if we select an option in one spinner in the other that option ceases to exist , what I did was the following : Whenever you click on the spinner it clears and adds all and then removes what is selected in the other so that you cannot select the same in both! But when I select something in one, it enters an infinite loop, as if I were always performing 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) {
}
});
}
First Disciplines and Second Disciplines are the content of Spinners Second if Spinner First and Spinner Second respectively.
Thank you very much and a good evening or good afternoon for Brazilians!