After the android spinner refills the data, the first item is displayed in setselection.

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.