Discussion on the return value of method Findfragmentbyid (int id) in fragment

Source: Internet
Author: User

When I learned the P124 page of the Android Programming Authority Guide, I ran into this code:

Cause my question if the judging condition is (fragment==null), that executes the last sentence fragment Fragment=fm.findfragmentbyid (R.id.fragmentcontainer); What exactly is the value of fragment? Through debug, I found that actually executed Fragment Fragment=fm.findfragmentbyid (r.id.fragmentcontainer), Fragment value is null, why is this? Refer to Google's official documentation of this method, there are two words: Finds A fragment that is identified by the given ID either when inflated from XML or as the contain  Er ID when added in a transaction. .......... Returns:the fragment if found or null otherwise. (because we did not define the fragment in the activity layout XML file, and did not add fragment with Fragmentmanager, so this method is not found the corresponding fragment, the return value is naturally null)

Discussion on the return value of method Findfragmentbyid (int id) in fragment

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.