当前位置:网站首页>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}}边栏推荐
- 数仓4.0(三)------数据仓库系统
- Methods commonly used interface automation test framework postman tests
- ExcelPatternTool: Excel table-database mutual import tool
- 刷爆朋友圈,Alibaba出品亿级并发设计速成笔记太香了
- [GYCTF2020]EasyThinking
- 接口自动化测试框架postman tests常用方法
- JZ搜索引擎solr研究-从数据库创建索引
- LiveVideoStackCon 2022 Shanghai Station opens tomorrow!
- 迅睿cms网站搬迁换了服务器后网站不能正常显示
- Creative code confession
猜你喜欢

Exercise: Selecting a Structure (1)

【Unity入门计划】2D游戏中遮挡问题的处理方法&伪透视

CNI (Container Network Plugin)

Transfer Learning - Distant Domain Transfer Learning

深度学习训练前快速批量修改数据集中的图片名

Xunrui cms website cannot be displayed normally after relocation and server change

The use of pytorch: temperature prediction using neural networks

如何基于OpenVINO POT工具简单实现对模型的量化压缩

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

MySQL learning
随机推荐
5. PCIe official example
原生js实现多选框全部选中和取消效果
为什么他们选择和AI恋爱?
Why is this problem reported when installing oracle11
习题:选择结构(一)
蓝牙Mesh系统开发五 ble mesh设备增加与移除
4. PCIe interface timing
程序员失眠时的数羊列表 | 每日趣闻
如何基于OpenVINO POT工具简单实现对模型的量化压缩
Three handshake and four wave in tcp
开篇-开启全新的.NET现代应用开发体验
hypervisor相关的知识点
iNFTnews | 对体育行业和球迷来说,NFT可以带来什么?
【机器学习】21天挑战赛学习笔记(二)
source program in assembly language
Day Fourteen & Postman
PHP Skills Assessment
优化Feed流遭遇拦路虎,是谁帮百度打破了“内存墙”?
Live playback including PPT download | Build Online Deep Learning based on Flink & DeepRec
"Configuration" is a double-edged sword, it will take you to understand various configuration methods