有没有一种方法来听FragmentManager的FragmentTransactions? [英] Is there a way to listen to FragmentTransactions of a FragmentManager?

查看:100
本文介绍了有没有一种方法来听FragmentManager的FragmentTransactions?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个片段它们相互作用相互的应用程序。有时候,我必须添加一个片段,有时我更换。

I have an app with several Fragments which interact to each other. Sometimes I have to add a Fragment, sometimes I replace it.

有没有办法听FragmentTransactions完成,所以我可以保持每次片段添加时间跟踪/显示/更换?

我已经试过 fragmentManager.addOnBackStackChangedListener(),但没有成功。

I've tried fragmentManager.addOnBackStackChangedListener() but unsuccessfully.

我觉得做一些对 onResume()所有的人的,但如果应用程序被切换到后台和前台我不应该做任何事情对我的UI。只有当我互动之间。

I thought of doing something on the onResume() of all of them, but if the app goes to background and foreground I should not do anything to my UI. Only when I interact between them.

任何帮助/战略是AP preciated。

Any help/strategy is appreciated.

编辑: 其理由是,我将在当前片段被显示的叠加。如果用户导航到任何其他的片段,我需要这个覆盖消失。

The reason is that I have an overlay that will be shown in the current Fragment. If the user navigates to any other Fragment, I need this overlay to disappear.

推荐答案

如果我给你正确的,你不需要听知道每次 - 你只需要知道,在您的应用程序的问候。如果是的话,写 FragmentHelper 类(或添加一些方法,以你的基础片段类,如果您有任何),敷 FragmentManager 它的方法,包括。所有额外的逻辑,跟踪或其他一切你需要在那里。

If I got you correctly you do not need to listen to know this everytime - you just need to know that in regards of your application. If so, write FragmentHelper class (or add some methods to your Base fragment class if you have any) and wrap FragmentManager methods with it, incl. all the additional logic, tracking or everything else you require there.

这篇关于有没有一种方法来听FragmentManager的FragmentTransactions?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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