当前位置:网站首页>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}}
边栏推荐
猜你喜欢
【机器学习】21天挑战赛学习笔记(二)
Introduction to JVM class loading
刷爆朋友圈,Alibaba出品亿级并发设计速成笔记太香了
10年测试经验,在35岁的生理年龄面前,一文不值
Log an error encountered when compiling google gn "I could not find a ".gn" file ..."
【Endnote】Word插入自定义形式的Endnote文献格式
使用OpenVINO实现飞桨版PGNet推理程序
day14--postman interface test
Use of pytorch: Convolutional Neural Network Module
Chapter 09 Use of Performance Analysis Tools [2. Index and Tuning] [MySQL Advanced]
随机推荐
2022 EdgeX中国挑战赛8月3日即将盛大开幕
如何发现一个有价值的 GameFi?
直播回放含 PPT 下载|基于 Flink & DeepRec 构建 Online Deep Learning
2022杭电多校第一场
执掌图表
Jin Jiu Yin Shi Interview and Job-hopping Season; Are You Ready?
居民用水问题
GCC: paths to header and library files
oracle将restful接口封装到视图中
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
[How to smash wool according to the music the couple listens to during the Qixi Festival] Does the background music affect the couple's choice of wine?
Residential water problems
hypervisor相关的知识点
进程在用户态和内核态的区别[独家解析]
C语言基础知识 -- 指针
Knowledge Points for Network Planning Designers' Morning Questions in November 2021 (Part 1)
如何基于OpenVINO POT工具简单实现对模型的量化压缩
蓝牙Mesh系统开发五 ble mesh设备增加与移除
基于OpenVINO工具套件简单实现YOLOv7预训练模型的部署
习题:选择结构(一)