About static constants I'm not feeling a bit.

Source: Internet
Author: User
Tags addall


    1. If a static variable is defined at the member location of a class, if the variable is initialized when the class is generated, it must be initialized in the constructor and not at the member location.

The actual development of the scene: friends to share, share the title in the background dynamic configuration, no network display the default value .

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/82/28/wKioL1dNPFSy440XAAAbxaNp6KE211.png "title=" Umengshare.png "alt=" Wkiol1dnpfsy440xaaabxanp6ke211.png "/>


Hell of a situation: in the case of a network, after sharing, and then the title of the network sharing is not the default title, but previously obtained from the network share title. Later I was struggling to think, in the member location is clearly initialized, how not to set the default title.

Problem solving: The final problem is also the static keyword, the static life cycle. The title is assigned a new value after the sharing succeeds in the case of the net, and when the title is in the Class (a Popwindow) reload, the title is not created with the creation of the Popwindow, but always exists, and retains the title of the previously shared web.


2. For adapter, if the data source is a static variable and the data source is changed, adapter does not need notifydatasetchanged to change the adapter UI.

Actual development scenario:Spinner Loading Data .

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/82/29/wKioL1dNP_KSv1s2AAB76zZ-IRQ441.png "title=" Screenshot_2016-05-31-15-31-41.png "alt=" Wkiol1dnp_ksv1s2aab76zz-irq441.png "/>


Teacher customization, is a Fragment,spinner data is managed by a class called Spinnerdata, all of which are static variables and methods, in entering the mainactivity through the GetType () this static method to request data, After the request succeeds, the data is parsed to the static list of classobjects.


error code 1: When the designer customizes this fragment initialization,

Classbeens.addall (spinnerdata.classobjects);

Actually, when I was debugging, Spinnerdata.classobjects had no real data. (The exception request initiated in Mainactivity has not successfully parsed the data)

error code 2: The author thinks there is data in the Spinnerdata, assigning the data to the spinner of the function

InitSpinner1 (context, spinner1, spinnerdata.typenames); InitSpinner2 (context, spinner2, spinnerdata.glassnames);

When I debug the spinnerdata.typenames,spinnerdata.classnames still have no data. Behind except

The left side of the spinner click will be linked to the right of the spinner, the other no spinner related data request operation.


Hell of a situation: Two spinner will have data!!!!!!!!!! So I guess the static data binding adapter don't need notify? Do the following experiment, to adapter binding static data source, when the button clicked only to change the static data source, when the ListView unexpectedly added new data!!!!!!!

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/82/2A/wKioL1dNQ5eAjz3qAAFPuY1j9z8264.png "title=" Aaaa.png "alt=" Wkiol1dnq5eajz3qaafpuy1j9z8264.png "/>

This explains how the two spinner data sources with no data at the start of the data display.

There is also another bug: If you do not click on the left side of the spinner, directly click on the right spinner, crash report Classbeans corner mark out of bounds. It's still a question of fragment at the beginning of this line of code.

Classbeens.addall (spinnerdata.classobjects);

Because the Spinnerdata gettype in Mainactivity is requesting a network method, it is not possible to know when the callback succeeds. So in the Spinnerdata class to write a listener, listen to its data callback success.

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/82/2A/wKioL1dNRXCzBgUUAAFRFts8-mY341.png "title=" Bbbbb.png "alt=" Wkiol1dnrxczbguuaafrfts8-my341.png "/>

Set up monitoring in fragment:

@Overridepublic void InitData () {//listens for changes in the data source because it is called asynchronously, and I don't know when the data has changed. Spinnerdata.setondatachangedlistener (this);

... }

@Overridepublic void Ondatachanged () {classbeens.clear (); Classbeens.addall (spinnerdata.classobjects);}



-------------------------------------------------------------------------------------

Sometimes the more such a heck of a problem, the more likely we are to have no real understanding of some of the concepts that result.

    1. Static

    2. Synchronous vs. asynchronous




This article is from the "line of the World" blog, please be sure to keep this source http://4259297.blog.51cto.com/4249297/1784811

About static constants I'm not feeling a bit.

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.