I have 3 Spinners inside a Fragment, the problem I'm having is when I spin the Tablet screen and the screen rebuilds, so the Spinners are reset.
The first Spinner comes from the bank, depending on the selection of the first Spinner the second is filled and so is the third Spinner when I choose the second.
I already deal with the data, because when selecting the item it already saves in the bank, however, when I turn the screen I have the problems described above, follows a method that I use to show the saved item even leaving the screen ...
public void setSpinnerSelection(Spinner spinner, Adapter adapter, String text) {
for (int i = 0; i < adapter.getCount(); i++) {
String comparar = adapter.getItem(i).toString();
if (comparar.equals(text)) {
spinner.setSelection(i);
}
}
}
I noticed something strange too, is it common when the fragment is rebuilt, does it perform what it has inside this Spinner method? "setOnItemSelectedListener", I realized that this is exactly the "bottleneck".
In short, I wanted to know a clever way to work with the fragment lifecycle.