使用片段设计应用程序
我开始开发一个基于片段的新应用程序。我想要实现的是类似于活动小组的东西。在片段中谈论我正在考虑开始创建一个 FragmentActivity(称为 TabActivity)来管理不同的选项卡。每个选项卡都是 ListFragment 的复合体,我需要根据用户输入启动不同的片段。我的想法是让 TabActivity 实现不同的 CallBackListener(一个用于 ListFragment),并根据调用的回调创建一个新片段。这是一个正确的解决方案吗?我发现文档有点令人困惑,有点令人沮丧......
TabActivity:
ListFragment1: fragment1 -> fragment2 -> fragment3
ListFragment2: fragment4 -> fragment5 -> fragment6
ListFragment3: fragment7 -> fragment8 -> fragment9
提前感谢
编辑:每个 ListFragment 共享相同的容器以显示其内容
I am starting developing a new application based on fragments. What I want to achieve is something similar to an activity group. Talking in fragments I was thinking to start create a FragmentActivity (call it TabActivity) that would manages different tabs. Every tab is compound of a ListFragment and I need to start different fragment based on the user input. My idea lets implement the TabActivity different CallBackListener (one for ListFragment) and, based on the call back called, create a new fragment. Could be this a correct solution? I found the documentation a bit confusing and a little frustrating...
TabActivity:
ListFragment1: fragment1 -> fragment2 -> fragment3
ListFragment2: fragment4 -> fragment5 -> fragment6
ListFragment3: fragment7 -> fragment8 -> fragment9
thanks in advance
EDIT: every ListFragment shares the same container in order to show their content
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我做了类似的事情,我有一个 Activity,它只是一个控制器/容器,用于在任何给定时间查看片段。
我在 Activity 上有一个方法,它接受足够的信息来确定要显示的片段,以及填充片段所需的包。然后,片段可以告诉活动它需要更改,或者使用该接口添加新的片段。
我的具体情况实际上使用相同的机制来控制父 Activity 布局中几个不同“片段容器”的内容。
I have done something similar where I have an Activity that is just a controller/container for what Fragments will be viewable at any given time.
I have a method on the Activity that accepts enough information to determine what Fragment is to be shown, and the bundle it needs to populate the Fragment. Fragments can then tell the activity that it needs to change out, or add the new Fragment using that interface.
My particular case actually uses the same mechanism to control the content of several different "fragment containers" in the layout of the parent Activity.