Onbuildheaders () in preferenceactivity

Source: Internet
Author: User
1. onbuildheaders (list <preferenceactivity. header>) in the previous blog (when to use preference headers), we described the role and use cases of preference headers. onbuildheaders is used to create and initialize headers in preferenceactivity.
After creating headers, We can reference the headers instance in the program, but pay attention to the creation time to avoid errors caused by referencing before the creation.
2. Call time
  • By analyzing the source code of preferenceactivity, we can see that the headers creation time is called in the oncreate () process, as shown below:

@ Override protected void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (COM. android. internal. r. layout. preference_list_content); mlistfooter = (framelayout) findviewbyid (COM. android. internal. r. id. list_footer); mprefscontainer = (viewgroup) findviewbyid (COM. android. internal. r. id. prefs_frame); Boolean hidingheaders = onishidingheaders (); msingdomainane = hidinghea Ders |! Onismultipane (); string initialfragment = getintent (). getstringextra (extra_show_fragment); bundle initialarguments = getintent (). getbundleextra (extra_show_fragment_arguments); int initialtitle = getintent (). getintextra (extra_show_fragment_title, 0); int initial0000title = getintent (). getintextra (extra_show_fragment_short_title, 0); If (savedinstancestate! = NULL) {// We are restarting from a previous saved state; used that to // initialize, instead of starting fresh. arraylist 

  • During oncreate () implementation in the inherited preferenceactivity, we must make it clear that the initialized headers can be referenced only after super. oncreate () is called. Otherwise, an error will occur.



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.