ViewPager与碎片 - 的onPause(),onResume()? [英] ViewPager with fragments - onPause(), onResume()?

查看:326
本文介绍了ViewPager与碎片 - 的onPause(),onResume()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用ViewPager与片段,我们在onPause(),onResume()方法不是选项卡之间移动时调用。有没有什么办法,我们可以在片段计算出,当我们正在可见还是被隐藏?

When using ViewPager with fragments, our onPause(), onResume() methods are not called when moving between tabs. Is there any way we can figure out in the fragment when we're being made visible or being hidden?

不幸的是我有逻辑onResume(),在onPause(),喜欢与位置服务注册,即永远不会切换标签时停止,因为在onPause()不会被调用,直到有退出的整个应用程序。

Unfortunately I have logic in onResume(), onPause(), like registering with location services, that never get stopped when switching tabs because onPause() never gets called until one exits the whole app.

感谢

推荐答案

在ViewPager自带的<一个href="http://developer.android.com/reference/android/support/v4/view/ViewPager.OnPageChangeListener.html"><$c$c>OnPageChangeListener接口。通过设置一些标志为previous和当前显示的页面,你可以效仿这种行为。

The ViewPager comes with the OnPageChangeListener interface. By setting some flags for the previous and currently shown pages, you can emulate this behavior.

这篇关于ViewPager与碎片 - 的onPause(),onResume()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆