当前位置:网站首页>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}}边栏推荐
- PHP Skills Assessment
- 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
- DDOS攻击真的是无解吗?不!
- (十七)51单片机——AD/DA转换
- 深度学习训练前快速批量修改数据集中的图片名
- XMjs跨域问题解决
- .Net C# 控制台 使用 Win32 API 创建一个窗口
- CMS建站流程
- ORA-00604 ORA-02429
- [Word] #() error occurs after Word formula is exported to PDF
猜你喜欢

MySQL3

英特尔 XDC 2022 精彩回顾:共建开放生态,释放“基建”潜能

hypervisor相关的知识点

MySQL3

Why is this problem reported when installing oracle11

Use of pytorch: Convolutional Neural Network Module

迅睿cms网站搬迁换了服务器后网站不能正常显示

PCIe Core Configuration
![[Unity Entry Plan] Handling of Occlusion Problems in 2D Games & Pseudo Perspective](/img/de/944b31c68cc5b9ffa6a585530e7be9.png)
[Unity Entry Plan] Handling of Occlusion Problems in 2D Games & Pseudo Perspective

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
随机推荐
如何基于OpenVINO POT工具简单实现对模型的量化压缩
ExcelPatternTool: Excel table-database mutual import tool
程序员失眠时的数羊列表 | 每日趣闻
Exploding the circle of friends, Alibaba produced billion-level concurrent design quick notes are too fragrant
dotnet 6 为什么网络请求不跟随系统网络代理变化而动态切换代理
【七夕如何根据情侣倾听的音乐进行薅羊毛】背景音乐是否会影响情侣对酒的选择
Utilities Methods commonly used interface automation test framework postman tests
Dynamic Programming/Knapsack Problem Summary/Summary - 01 Knapsack, Complete Knapsack
基于OpenVINO工具套件简单实现YOLOv7预训练模型的部署
释放技术创新引擎,英特尔携手生态合作伙伴推动智慧零售蓬勃发展
Method Overriding and Object Class
PHP技能评测
GCC: compile-time library path and runtime library path
【TA-霜狼_may-《百人计划》】图形4.3 实时阴影介绍
Greenplum数据库故障分析——版本升级后gpstart -a为何返回失败
为什么他们选择和AI恋爱?
IJCAI2022 | DictBert:采用对比学习的字典描述知识增强的预训练语言模型
刷爆朋友圈,Alibaba出品亿级并发设计速成笔记太香了
How to create an rpm package