当前位置:网站首页>Fragment visibility judgment
Fragment visibility judgment
2022-08-05 01:52:00 【TomCat...】
1. Fragment is used between activities:
This situation is the simplest, because the life cycle of the fragment at this time is consistent with the life cycle of the activity.When there is another activity, as long as you monitor the onResume and onPause methods of Fragment, you can judge whether it is displayed or hidden (as for the meaning of these two methods, I will not say more, if you don’t understand, go to the life cycle of activity and fragment by yourself)
@Overridepublic void onResume() {super.onResume();}@Overridepublic void onPause() {super.onPause();}
2. Fragment in ViewPager
The onResume() and onPause() methods will not be called when the Fragment in ViewPager is switched left and right.Because these two methods follow the life cycle of the activity, at this time we can reset the setUserVisibleHint(boolean isVisibleToUser) method in the fragment to monitor whether the Fragment is visible
@Overridepublic voidsetUserVisibleHint(booleanisVisibleToUser) {super.setUserVisibleHint(isVisibleToUser);if(isVisibleToUser){//visible}else{//Invisible}}
3. Use the show() and hide() methods to display and hide fragments
In this case, the fragment is switched to another fragment in an activity, then the above two monitors you willIt is useless to find it. At this time, we can listen to the onHiddenChanged(boolean hidden) method to determine whether it is visible to the user.
@Overridepublic void onHiddenChanged(booleanhidden) {super.onHiddenChanged(hidden);if(hidden){//Invisible}else{//visible}}
边栏推荐
- Greenplum数据库故障分析——能对数据库base文件夹进行软连接嘛?
- 安装oracle11的时候为什么会报这个问题
- 深度学习训练前快速批量修改数据集中的图片名
- 多线程涉及的其它知识(死锁(等待唤醒机制),内存可见性问题以及定时器)
- Understand the recommendation system in one article: Recall 06: Two-tower model - model structure, training method, the recall model is a late fusion feature, and the sorting model is an early fusion
- Residential water problems
Utilities - Method Overriding and Object Class
- (十七)51单片机——AD/DA转换
- 蓝牙Mesh系统开发四 ble mesh网关节点管理
猜你喜欢
1349. 参加考试的最大学生数 状态压缩
day14--postman interface test
MySQL learning
“嘀哩哩,等灯等灯”,工厂安全生产的提示音
Chapter 09 Use of Performance Analysis Tools [2. Index and Tuning] [MySQL Advanced]
5. PCIe official example
硬实力和软实力,哪个对测试人来说更重要?
KingbaseES V8 GIS数据迁移方案(2. Kingbase GIS能力介绍)
如何发现一个有价值的 GameFi?
CNI (Container Network Plugin)
随机推荐
torch.autograd.grad finds the second derivative
[Redis] Redis installation under Linux
JZ搜索引擎solr研究-从数据库创建索引
短域名绕过及xss相关知识
ExcelPatternTool: Excel table-database mutual import tool
day14--postman interface test
原生js实现多选框全部选中和取消效果
详细全面的postman接口测试实战教程
The use of pytorch: temperature prediction using neural networks
张驰咨询:揭晓六西格玛管理(6 Sigma)长盛不衰的秘密
意识形态的机制
行业现状?互联网公司为什么宁愿花20k招人,也不愿涨薪留住老员工~
Jin Jiu Yin Shi Interview and Job-hopping Season; Are You Ready?
10年测试经验,在35岁的生理年龄面前,一文不值
使用OpenVINO实现飞桨版PGNet推理程序
[Word] #() error occurs after Word formula is exported to PDF
亚马逊云科技携手中科创达为行业客户构建AIoT平台
ORA-00604 ORA-02429
为什么他们选择和AI恋爱?
.Net C# 控制台 使用 Win32 API 创建一个窗口