Android: how to set the default value after data is filled in by the spinner [Android]

Source: Internet
Author: User

For details about the basic functions of the spinner, refer to androidgui03: common skills of the spinner.

 

Update:

The project has an interface that uses the choice of the spinner and then automatically reload the listview. At the beginning, the listview is manually added during oncreate. setadapter () is used to load data. Now it is not necessary. listview is also available in the onitemselected method of the spinner. setadapter () (this is used for loading). During debugging, it is found that the data is loaded twice. Originally, if you have a spinner, the system automatically calls onitemselected (and starts with the first item), which leads to duplicate load with my oncreate.

 

Update:

If you want to implement a data jump from the selected items of the previous listview to view2, The listview will jump back to the data of the items corresponding to the previous spinner. At the beginning, I only changed the textview word in onitemselected, and then changed the position when loading. Soon I found that this was just a pseudo practice, the selection items in the spinner are certainly unchanged. Now we find that android has a spinner. setselection (n, true) to select the selected item. Use this.

Previously, it was found that the first operation is selected by default after data adaptation. By default, the first operation is not executed immediately, but executed after a period of time, and the onitemselectedlistener event is triggered. However, if youUse spinner. setselection (2, true); Then, the system will not execute onitemselected at the beginning.

[Android] how to set the default value after data is filled in for the spinner?

 

 

Updata:

Found:
At the beginning, the system does not call onitemselected and the sequence of setonitemselectedlistener (this); setselection (spinneritem, true:

 

// Call onitemselected

Spinner. setonitemselectedlistener (this );
Spinner. setselection (spinneritem, true );

 

The onitemselected statement is not called if the two statements are exchanged.

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.