When two spinner links are performed, spinner2 fills in data based on the choice of spinner1, and then uses setseletion (2) to set the default item. The result shows that the first entry is displayed on the spinner2 page, but the position of Position 2 is selected.
Solution:
Old Code:
Spinner. setadapter (adapter );
Spinner. setselection (2 );
Solution 2:
(1)
Spinner. setadapter (adapter );
Spinner. setselection (2, true); // the spinner will re-Layout
(2) Recommendation
Spinner. setadapter (adapter );
Adapter. notifydatasetchanged ();// Notify the spinner to refresh the data
Spinner. setselection (2 );
So what is the cause? I think this is a bug. This usually happens after the data is refilled. In addition, the setselection (INT position) can be correctly displayed.
There is a big difference between setselection (INT position, Boolean animate) and setselection (INT position) implementation mechanisms. when the former is called, the layout function is re-triggered to immediately trigger the onitemselected function, which is equivalent to clicking it by hand. The latter sets the position to be selected next time: setnextselectedpositionint (position); then requests layout; while requestlayout is not executed immediately, it is just a schedule. However, some statuses may be lost when the latter reloads the data and layout.
BTW: a detailed introduction to the spindle summary http://www.blogjava.net/crazycoding/archive/2011/07/09/353981.html