当前位置:网站首页>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
边栏推荐
- LeetCode #101. Symmetric Binary Tree
- 【HCIP持续更新】IS-IS协议原理与配置
- Apexsqlrecover无法连接数据库
- Flutter入门进阶之旅(七)GestureDetector
- Report: The number of students who want to learn AI has increased by 200%, and there are not enough teachers
- 苹果Meta都在冲的Pancake技术,中国VR团队YVR竟抢先交出产品答卷
- How to upload local file trial version in binary mode in ABAP report
- MySQL 原理与优化,Group By 优化 技巧
- 随机快排时间复杂度是N平方?
- 在“Extend the Omniverse”比赛中构建用于 3D 世界的工具
猜你喜欢
Flutter Getting Started and Advanced Tour (2) Hello Flutter
900页数学论文证明旋转的黑洞不会爆炸,丘成桐:30多年来广义相对论首次重大突破...
中断系统结构及中断控制详解
Compensation transaction and idempotency guarantee based on CAP components
The batch size does not have to be a power of 2!The latest conclusions of senior ML scholars
AQS同步组件-FutureTask解析和用例
MongoDB-查询中$all的用法介绍
Fragment中嵌套ViewPager数据空白页异常问题分析
MySQL principle and optimization of Group By optimization techniques
HAproxy: load balancing
随机推荐
MongoDB-查询中$all的用法介绍
1-hour live broadcast recruitment order: industry big names share dry goods, and enterprise registration opens丨qubit·viewpoint
Common gadgets of Shell (sort, uniq, tr, cut)
用场景定义硬件,英码科技破解“边缘计算”密码
Information system project managers must memorize the core test sites (63) The main process of project portfolio management & DIPP analysis
Scala 高阶(七):集合内容汇总(上篇)
2022牛客多校(六)M. Z-Game on grid
Glory to the Blue Yonder, speeds up the strategic growth
Apexsqlrecover cannot connect to database
#Internet of Things essay#Xiaoxiong pie equipment development actual combat
金融业“限薪令”出台/ 软银出售过半阿里持仓/ DeepMind新实验室成立... 今日更多新鲜事在此...
读写分离后,性能居然提升100%了呀
FFmpeg库在win10上配置使用(不配置libx264)
自定义VIEW实现应用内消息提醒上下轮播
The latest interview summary in 20022 brought by Ali senior engineer is too fragrant
Resolved IndentationError: unindent does not match any oute r indentation Level
AQS Synchronization Component - FutureTask Analysis and Use Cases
ABAP 报表中如何以二进制方式上传本地文件试读版
【无标题】
西湖大学教授怎么看AI制药革命?|量子位智库圆桌实录