当前位置:网站首页>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
边栏推荐
- WeChat payment development process
- Win10 compiles the x264 library (there are also generated lib files)
- API调用,API传参,面向对接开发,你真的会写接口文档吗?
- Flutter入门进阶之旅(七)GestureDetector
- Flutter入门进阶之旅(十)Dialog&Toast
- Flutter入门进阶之旅(五)Image Widget
- 数据挖掘-06
- 金融业“限薪令”出台/ 软银出售过半阿里持仓/ DeepMind新实验室成立... 今日更多新鲜事在此...
- 报告:想学AI的学生数量已涨200%,老师都不够用了
- 【无标题】
猜你喜欢

Flutter入门进阶之旅(七)GestureDetector

MySQL principle and optimization of Group By optimization techniques

AQS Synchronization Component - FutureTask Analysis and Use Cases

HAproxy: load balancing

JD.com architects tidy up: what are the core technical knowledge points of jvm and performance tuning

ABAP 面试题:如何使用 ABAP 编程语言的 System CALL 接口,直接执行 ABAP 服务器所在操作系统的 shell 命令?

国产抗新冠口服药每瓶不超300元/ 我国IPv6网络全面建成/ 谷歌入局折叠屏手机...今日更多新鲜事在此...

两分钟录音就可秒变语言通!火山语音音色复刻技术如何修炼而成?

Too much volume... Tencent was asked on the side that the memory was full, what would happen?

The grep command Shell regular expressions, the three musketeers
随机推荐
[Microservice ~ Remote Call] Integrate RestTemplate, WebClient, Feign
#物联网征文#小熊派设备开发实战
在北极都可以穿短袖了,温度飙升至32.5℃
Rust from entry to proficient 04 - data types
关于Retrofit网络请求URL中含有可变参数的处理
Information system project managers must memorize the core test sites (63) The main process of project portfolio management & DIPP analysis
曲鸟全栈UI自动化教学(八):框架代码讲解和进一步优化
The redis library cannot be imported
告别手摇织布机的AI时代
曼城推出可检测情绪的智能围巾,把球迷给整迷惑了
K个结点的组内逆序调整
ansible-cmdb friendly display ansible collects host information
Rust从入门到精通04-数据类型
Compensation transaction and idempotency guarantee based on CAP components
00后写个暑假作业,被监控成这笔样
二叉树的序列化和反序列化
The new features of ABP 6.0.0 - rc. 1
Flutter入门进阶之旅(八)Button Widget
腾讯欲成育碧最大股东/ 米哈游招NLP内容生成研究员/ AI发现四千余物种濒临灭绝...今日更多新鲜事在此...
无需精子卵子子宫体外培育胚胎,Cell论文作者这番话让网友们炸了