当前位置:网站首页>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}}
边栏推荐
- The use of pytorch: temperature prediction using neural networks
- EBS利用虚拟列及hint 提示优化sql案例一则
- Greenplum数据库故障分析——版本升级后gpstart -a为何返回失败
- 行业现状?互联网公司为什么宁愿花20k招人,也不愿涨薪留住老员工~
- 接口自动化测试框架postman tests常用方法
- (十七)51单片机——AD/DA转换
- Is DDOS attack really unsolvable?Do not!
- 亚马逊云科技携手中科创达为行业客户构建AIoT平台
- dotnet 6 为什么网络请求不跟随系统网络代理变化而动态切换代理
- 习题:选择结构(一)
猜你喜欢
MySQL3
蓝牙Mesh系统开发四 ble mesh网关节点管理
Dynamic Programming/Knapsack Problem Summary/Summary - 01 Knapsack, Complete Knapsack
数仓4.0(三)------数据仓库系统
记录谷歌gn编译时碰到的一个错误“I could not find a “.gn“ file ...”
Leetcode刷题——22. 括号生成
10年测试经验,在35岁的生理年龄面前,一文不值
MySQL learning
1349. 参加考试的最大学生数 状态压缩
Log an error encountered when compiling google gn "I could not find a ".gn" file ..."
随机推荐
[GYCTF2020]EasyThinking
The use of pytorch: temperature prediction using neural networks
The difference between a process in user mode and kernel mode [exclusive analysis]
使用OpenVINO实现飞桨版PGNet推理程序
迁移学习——Distant Domain Transfer Learning
深度学习训练前快速批量修改数据集中的图片名
刷爆朋友圈,Alibaba出品亿级并发设计速成笔记太香了
<开发>实用工具
Oracle encapsulates restful interfaces into views
Is DDOS attack really unsolvable?Do not!
GCC: paths to header and library files
Bit rate vs. resolution, which one is more important?
Jin Jiu Yin Shi Interview and Job-hopping Season; Are You Ready?
Day Fourteen & Postman
行业现状?互联网公司为什么宁愿花20k招人,也不愿涨薪留住老员工~
【TA-霜狼_may-《百人计划》】图形4.3 实时阴影介绍
新来个技术总监,把DDD落地的那叫一个高级,服气
一文看懂推荐系统:召回06:双塔模型——模型结构、训练方法,召回模型是后期融合特征,排序模型是前期融合特征
1349. 参加考试的最大学生数 状态压缩
[parameters of PyQT5 binding functions]