当前位置:网站首页>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
边栏推荐
- 罗振宇折戟创业板/ B站回应HR称用户是Loser/ 腾讯罗技年内合推云游戏掌机...今日更多新鲜事在此...
- ThreadLocal的简单理解
- 26、管道参数替换命令xargs
- #物联网征文#小熊派设备开发实战
- h264协议
- LeetCode #101. Symmetric Binary Tree
- Information system project managers must memorize the core test sites (63) The main process of project portfolio management & DIPP analysis
- 荣耀携手Blue Yonder,加快企业战略增长
- The new features of ABP 6.0.0 - rc. 1
- 史上最猛“员工”,疯狂吐槽亿万富翁老板小扎:那么有钱,还总穿着同样的衣服!...
猜你喜欢
报告:想学AI的学生数量已涨200%,老师都不够用了
新起之秀 DPU,正在掀起数据中心变革!
Win10 compiles the x264 library (there are also generated lib files)
Say goodbye to the AI era of hand looms
Flutter Getting Started and Advanced Tour (3) Text Widgets
MongoDB-查询中$all的用法介绍
Common gadgets of Shell (sort, uniq, tr, cut)
AQS Synchronization Component - FutureTask Analysis and Use Cases
李开复花上千万投的缝纫机器人,团队出自大疆
阿里高工带来的20022最新面试总结太香了
随机推荐
Win10 compiles the x264 library (there are also generated lib files)
智驾科技完成C1轮融资,此前2轮已融4.5亿元
2022 Niu Ke Duo School (6) M. Z-Game on grid
WebView注入Js代码实现大图自适应屏幕点击图片预览详情
Resolved IndentationError: unindent does not match any oute r indentation Level
发明时代,「幂集创新」事关你我
MongoDB-查询中$all的用法介绍
Go 事,如何成为一个Gopher ,并在7天找到 Go 语言相关工作,第1篇
Fragment中嵌套ViewPager数据空白页异常问题分析
glide工具类的简单封装
MySQL principle and optimization of Group By optimization techniques
你没见过的《老友记》镜头,AI给补出来了|ECCV 2022
二叉树的序列化和反序列化
Glory to the Blue Yonder, speeds up the strategic growth
阿里高工带来的20022最新面试总结太香了
Report: The number of students who want to learn AI has increased by 200%, and there are not enough teachers
生成上传密钥和密钥库
读写分离后,性能居然提升100%了呀
Too much volume... Tencent was asked on the side that the memory was full, what would happen?
1小时直播招募令:行业大咖干货分享,企业报名开启丨量子位·视点