当前位置:网站首页>ViewPager fragments of nested data blank page abnormal problem analysis
ViewPager fragments of nested data blank page abnormal problem analysis
2022-08-09 13:17:00 【Xie Dong_】
开题思考:Fragment放ViewPager,ViewPager里面是fragment.第一次进入没问题,再次进入ViewPager的fragment时里面内容就没了,A data blank page exception occurs.
描述:activityPut two inFragment,Pages to be reviewed respectively、Added page;which is pending reviewfragment中利用viewpager放了三个fragment,All respectively、审核加入、Audit exit,The second switch is pending review、已加入fragment时,will be found pending reviewfragment中ViewPager承载的FragmentData blank pages will appear.如下图所示:
It feels like it is based on experienceFragmentManager出了问题,因为FragmentManagerThe responsibility is to be responsible for managementFragment,包括对Fragment栈中的Fragement进行添加,删除,替换等操作,Since there is a blank page,肯定是FragmentManager在进行FragmentNot working properly when replacing,查看Fragment以及FragmentActivityThere are three types of source code foundFragmentManager,分别为getFragmentManager、getSupportFragmentManager、getChildFragmentManager;其中getFragmentManager跟getChildFragmentManager在Fragment类中,而getSupportFragmentManager位于FragmentActivity中,而getFragmentManager虽然在Fragment中,But it is mentioned at the end of the official note,如果当前Fragment是另外一个Fragment的子类,则当前FragmentManager属于父类,这就意味着,Although the three are similar, the objects of management are different.
The source code of the three is as follows:
getFragmentManager:
/**
* Return the FragmentManager for interacting with fragments associated
* with this fragment's activity. Note that this will be non-null slightly
* before {@link #getActivity()}, during the time from when the fragment is
* placed in a {@link FragmentTransaction} until it is committed and
* attached to its activity.
*
* <p>If this Fragment is a child of another Fragment, the FragmentManager
* returned here will be the parent's {@link #getChildFragmentManager()}.
*/
final public FragmentManager getFragmentManager() {
return mFragmentManager;
}
getSupportFragmentManager:
/**
* Return the FragmentManager for interacting with fragments associated
* with this activity.
*/
public FragmentManager getSupportFragmentManager() {
return mFragments.getSupportFragmentManager();
}
getChildFragmentManager:
/**
* Return a private FragmentManager for placing and managing Fragments
* inside of this Fragment.
*/
final public FragmentManager getChildFragmentManager() {
if (mChildFragmentManager == null) {
instantiateChildFragmentManager();
if (mState >= RESUMED) {
mChildFragmentManager.dispatchResume();
} else if (mState >= STARTED) {
mChildFragmentManager.dispatchStart();
} else if (mState >= ACTIVITY_CREATED) {
mChildFragmentManager.dispatchActivityCreated();
} else if (mState >= CREATED) {
mChildFragmentManager.dispatchCreate();
}
}
return mChildFragmentManager;
}
根据google官方的描述(PS:EnglishSelf-translation is out of the question),大意为getFragmentManager、跟getSupportFragmentManagerIs to get manageable and currentActivity有关联的Fragment的FragmentManager,That is to say, the two belong to each otherActivity的,再来看下getChildFragment的官方注释
/**
* Return a private FragmentManager for placing and managing Fragments
* inside of this Fragment.
*/
final public FragmentManager getChildFragmentManager() {
The above comment roughly means returning a private oneFragmentManager来管理Fragment,它属于Fragment.So far, the whole problem has been sorted out,Because of the question raised in the title of the article,是在Fragment中使用ViewPager装载Fragment,也就是说,在Fragmentshould be used in Fragemnt类中提供的manager方法,即在给ViewPager设置FragmentManager的时候应该使用getChildFragmentManager.
As mentioned in the title of the articleViewPager设置Adapter:
viewPager.setAdapter(new ManageFragmentPagerAdapter(getFragmentManager(), list));
After analysis, it should be modified to:
viewPager.setAdapter(new ManageFragmentPagerAdapter(getChildFragmentManager(), list));
归纳总结:getFragmentManager()所得到的是所在fragment 的父容器的管理器,而getChildFragmentManager()所得到的是在fragment
边栏推荐
- 中科院打脸谷歌:普通电脑追上量子优越性,几小时搞定原本要一万年的计算...
- AI篮球裁判火了,走步算得特别准,就问哈登慌不慌
- 如何修改data work上jdbc驱动的版本
- 中断系统结构及中断控制详解
- 十分钟教会你如何使用VitePress搭建及部署个人博客站点
- Manchester city launch emotional intelligence scarf can be detected, give the fans
- 手写大根堆
- 超越CLIP的多模态模型,只需不到1%的训练数据!南加大最新研究来了
- 一甲子,正青春,CCF创建六十周年庆典在苏州举行
- 非科班AI小哥火了:他没有ML学位,却拿到DeepMind的offer
猜你喜欢
The latest interview summary in 20022 brought by Ali senior engineer is too fragrant
Win10 compiles the x264 library (there are also generated lib files)
【HCIP持续更新】IS-IS协议原理与配置
HAproxy:负载均衡
西湖大学教授怎么看AI制药革命?|量子位智库圆桌实录
[Microservice ~ Remote Call] Integrate RestTemplate, WebClient, Feign
Batch大小不一定是2的n次幂!ML资深学者最新结论
redis库没法引入
京东架构师呕心整理:jvm与性能调优有哪些核心技术知识点
MySQL principle and optimization of Group By optimization techniques
随机推荐
Say goodbye to the AI era of hand looms
中科院打脸谷歌:普通电脑追上量子优越性,几小时搞定原本要一万年的计算...
900页数学论文证明旋转的黑洞不会爆炸,丘成桐:30多年来广义相对论首次重大突破...
Blocking, non-blocking, multiplexing, synchronous, asynchronous, BIO, NIO, AIO all in one pot
Simple encapsulation of glide tool class
FFmpeg在win10上编译安装(配置libx264)
太卷了... 腾讯一面被问到内存满了,会发生什么?
【无标题】
Intranet penetration tool ngrok usage tutorial
国产抗新冠口服药每瓶不超300元/ 我国IPv6网络全面建成/ 谷歌入局折叠屏手机...今日更多新鲜事在此...
Fragment中嵌套ViewPager数据空白页异常问题分析
Flutter Getting Started and Advanced Tour (3) Text Widgets
Apexsqlrecover无法连接数据库
你没见过的《老友记》镜头,AI给补出来了|ECCV 2022
The new features of ABP 6.0.0 - rc. 1
WeChat payment development process
苹果Meta都在冲的Pancake技术,中国VR团队YVR竟抢先交出产品答卷
我们真的需要DApp吗?App真的不能满足我们的幻想吗?
如何修改data work上jdbc驱动的版本
1-hour live broadcast recruitment order: industry big names share dry goods, and enterprise registration opens丨qubit·viewpoint