Getfragmentmanager and Getchildfragmentmanager, solving fragment white screen

Source: Internet
Author: User

Getfragmentmanager to the manager of the included fragment, and if fragment nested fragment, then Getchildfragmentmanager () will be used.
Getfragmentmanager to the manager of the included fragment, and if fragment nested fragment, then Getchildfragmentmanager () will be used.
Encountered while using fragment
The use of Getfragmentmanager () and Getchildfragmentmanager (),
Getfragmentmanager () is the fragment management of the parent container where the fragment is located,
Getchildfragmentmanager () is the fragment management of the sub-container inside the fragment.

Getfragmentmanager to the manager of the included fragment, and if fragment nested fragment, then Getchildfragmentmanager () will be used.

Fragment nesting fragment to use Getchildfragmentmanager.

Encounter a problem, fragment put Viewpager,viewpager inside is fragment. First Entry no problem, again into the Viewpager fragment when the content is gone, data loss.

Fragmentpageradapter. Log found Fragmentpageradapter GetItem will not be called, has been unable to find the reason. The reply to the Internet finally found the answer.

Originally inside the fragment with or getfragmentmanager,fragment nested fragment, inside to use Getchildfragmentmanager.

Fragmentmanager Childfragmentmanager = Getchildfragmentmanager ();
Viewpager_adapter viewpager_adapter = new Viewpager_adapter (Childfragmentmanager, fragments); Fragmentpageradapter

The definition of IS getChildFragmentManager() :

Return a private Fragmentmanager for placing and managing fragments inside of this Fragment.

Meanwhile the definition of is getFragmentManager() getSupportFragmentManager() :

Return the Fragmentmanager for interacting with fragments associated and this fragment ' s activity.

Basically, the difference is that Fragment's now has their own internal that FragmentManager can handle fragments. The child Fragmentmanager is the one, handles fragments contained within only the Fragment, it was added to. The other fragmentmanager is contained within the entire Activity .

In this case, what I'm guessing is your ' ve added the fragments to the Activity ' s fragmentmanager. You get the child fragmentmanager which doesn ' t contain what is looking for. Thus get the exception because it can ' t find the Fragment with the given ID because it's in a different fragmentmanage R.

That is, the child fragmentmanager is the fragment you apply, and Fragmentmanager is included in the activity, it is possible to find the corresponding fragment fragment of the situation and display blank.

=============================================

Msectionspageradapter = new Sectionspageradapter (getactivity (). Getsupportfragmentmanager ());

In fragment nested fragment words, do not use the above sentence ... will appear in the Viewpager. Some fragment will not load the situation ... Both Viewpager loading Fragment blank pages ....

So fragment inside nested fragment words: Must use Getchildfragmentmanager ();

Msectionspageradapter = new Sectionspageradapter (Getchildfragmentmanager ());

Getfragmentmanager and Getchildfragmentmanager, solving fragment white screen

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.