码迷,mamicode.com
首页 > 其他好文 > 详细

转 区别 getChildFragmentManager getSupportFragmentManager

时间:2015-03-06 15:31:01      阅读:312      评论:0      收藏:0      [点我收藏+]

标签:

The definition of getChildFragmentManager() is:

Return a private FragmentManager for placing and managing Fragments inside of this Fragment.

Meanwhile the definition of getFragmentManager() (or in this case getSupportFragmentManager()) is:

Return the FragmentManager for interacting with fragments associated with this fragment‘s activity.

Basically, the difference is that Fragment‘s now have their own internal FragmentManager that can handle Fragments. The child FragmentManager is the one that handles Fragments contained within only the Fragment that it was added to. The other FragmentManager is contained within the entire Activity.

In this case, what I‘m guessing is you‘ve added the Fragments to the Activity‘s FragmentManager. You get the child FragmentManager which doesn‘t contain what you are looking for. Thus you get the exception because it can‘t find the Fragment with the given ID because it‘s in a different FragmentManager.

 

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

mSectionsPagerAdapter = new SectionsPagerAdapter(getActivity().getSupportFragmentManager());

在Fragment里面嵌套Fragment 的话,不要用上面的那句。。。会在ViewPager中出现。有些Fragment 不会加载的情况。。。既ViewPager 加载 Fragment 空白页的情况。。。。

所以   Fragment里面嵌套Fragment 的话:一定要用getChildFragmentManager();

  mSectionsPagerAdapter = new SectionsPagerAdapter(getChildFragmentManager());

转 区别 getChildFragmentManager getSupportFragmentManager

标签:

原文地址:http://www.cnblogs.com/wikiki/p/4318162.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!