I have a activity that have many cascaded spinner and after select first one, second spinner initialize and fill data and after select item from second, third spinner initialize and fill data and so on.
for each spinner I create them like this and it is iterative:
public ArrayList<MaterialSpinner> spinnerlist = new ArrayList<>();
public void createView(){
final MaterialSpinner spinner = new MaterialSpinner(context);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener(){//...after select item next spinner creates with calling createView() iteratively}
loadSpinnerData(); // set adapter and more
spinnerlist.add(spinner);
}
every things go right when select is by user, but when I use setSelection(positionOfItem)
Dynamically, unfortunately
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
do not calls. I do not know why this happens.
for (int i = 0; i < some_value; i++) {
int positionOfItem = get_proper_position;
spinnerList.get(i).setSelection(positionOfItem); //this not trigger onItemSelect!
}
the problem is here. spinner size is 1 in first time, but after setselection , listener do not calls and second spinner do not creates.
I also thought this is because of time consuming action so try to use a run-able and post some delay but it not worked.