转 区别 getChildFragmentManager getSupportFragmentManager

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());

时间: 2024-08-30 17:23:18

转 区别 getChildFragmentManager getSupportFragmentManager的相关文章

FragmentTransaction的commit和commitAllowingStateLoss的区别

1.什么是FragmentTransaction? 使用Fragment时,可以通过用户交互来执行一些动作,比如增加.移除.替换等. 所有这些改变构成一个集合,这个集合被叫做一个transaction. 可以调用FragmentTransaction中的方法来处理这个transaction,并且可以将transaction存进由activity管理的back stack中,这样用户就可以进行fragment变化的回退操作. 可以这样得到FragmentTransaction类的实例: Fragm

app包中的fragment和v4包中的fragment的使用的区别

1.错误:The method replace(int, Fragment) in the type FragmentTransaction is not applicable for the arguments (int, MyFragment) http://www.cnblogs.com/1114250779boke/p/3867494.html 其实主要问题是getSupportFragmentManager(),而不是使用getFragmentManager 2.app包中的fragm

getFragmentManager与getChildFragmentManager,解决fragment白屏

getFragmentManager到的是activity对所包含fragment的Manager,而如果是fragment嵌套fragment,那么就需要利用getChildFragmentManager()了.getFragmentManager到的是activity对所包含fragment的Manager,而如果是fragment嵌套fragment,那么就需要利用getChildFragmentManager()了.在使用fragment时 遇到 getFragmentManager()

Fragment的startActivityForResult和Activity的startActivityForResult的区别

2016-08-30 18:22:33 前提:我们的APP要兼容Api level 11以前的,所以必须用FragmentActivity 1.对于Fragment的,我们很多时候都会在Activity中通过如下方式使用: Fragment是Android3.0以后才引入的东西,为了向下兼容,在support v4包中加入了FragmentActivity,FragmentActivity和Activity的区别是:FragmentActivity中只能使用getSupportFragmentM

Nginx 反代参数:$X-Real-Ip和$X-Forwarded-For的区别

## \$X-Real-Ip和$X-Forwarded-For的区别 标签(空格分隔): nignx 负载均衡 client-ip --- ####1.如果只有一层代理,这两个头的值就是一样的####2.多层代理> * X-Forwarded-For:  header包含这样一行        `*X-Forwarded-For: 1.1.1.1, 2.2.2.2, 3.3.3.3*`> * X-Real-Ip:没有相关标准,上面的例子,如果配置了X-Read-IP,可能会有两种情况`// 最

C#中Convert和parse的区别

Convert.ToInt32()与int.Parse()的区别(1)这两个方法的最大不同是它们对null值的处理方法: Convert.ToInt32(null)会返回0而不会产生任何异常,但int.Parse(null)则会产生异常. 没搞清楚Convert.ToInt32和int.Parse()的细细微区别时千万别乱用,否则可能会产生无法预料的结果,举例来说:假如从url中取一个参数page的值,我们知道这个值是一个int,所以即可以用Convert.ToInt32(Request.Que

python判断字符串,str函数isdigit、isdecimal、isnumeric的区别

s为字符串s.isalnum() 所有字符都是数字或者字母s.isalpha() 所有字符都是字母s.isdigit() 所有字符都是数字s.islower() 所有字符都是小写s.isupper() 所有字符都是大写s.istitle() 所有单词都是首字母大写,像标题s.isspace() 所有字符都是空白字符.\t.\n.\r 判断是整数还是浮点数a=123b=123.123 >>>isinstance(a,int)True>>>isinstance(b,floa

java web 过滤器跟拦截器的区别和使用

1.首先要明确什么是拦截器.什么是过滤器 1.1 什么是拦截器: 拦截器,在AOP(Aspect-Oriented Programming)中用于在某个方法或字段被访问之前,进行拦截然后在之前或之后加入某些操作.拦截是AOP的一种实现策略. 在Webwork的中文文档的解释为--拦截器是动态拦截Action调用的对象.它提供了一种机制可以使开发者可以定义在一个action执行的前后执行的代码,也可以在一个action执行前阻止其执行.同时也是提供了一种可以提取action中可重用的部分的方式.

mysql中int、bigint、smallint和tinyint的区别与长度

对比发现 int bigint smallint 和 tinyint 类型,如果创建新表时没有指定 int(M) 中的M时,默认分别是 : int             -------     int(11) bigint       -------     bigint(20) smallint   -------     smallint(6) tinyint     -------     tinyint(4) 下面是这几种类型的取值范围 参考:http://www.2cto.com/d