(ActionBar) 选项卡 +寻呼机 + ViewPager 容器内的详细片段
对于 ActionBarSherlock 我想要(操作栏)选项卡 + 寻呼机。我在寻呼机容器内使用片段。我已经得到了 http://actionbarsherlock.com/ 工作的示例,但我无法设法在该寻呼机容器内获取详细信息片段当我单击第一个片段中的列表项时。
是否不可能有这样的东西:
带有选项卡和寻呼机容器的 Activity
- Tab1 下的寻呼机容器内的片段 A
- 单击片段 A 中的某些内容,并在 Tab1 下的同一寻呼机容器中显示片段 B。
然后片段 A 不可见,只有片段 B 可见,而且所有选项卡也可见。
目前我认为只有在单击片段 A 中的某些内容后才能启动一个新活动(将片段 B 保存在其中)。
For ActionBarSherlock I would like to have (Action Bar) Tabs + Pager. I use Fragments inside that pager container. I already got the examples of http://actionbarsherlock.com/ working, but I can't manage to get a details fragment inside that pager container when I would click on let's say a listitem in the first fragment.
Is it impossible to have something like this:
Activity with Tabs and pager container
- Fragment A inside pager container under Tab1
- Click on something in Fragment A and show Fragment B in same pager container under Tab1.
Fragment A is then not visible, only Fragment B is visible, but also all the Tabs.
At the moment I think only a new activity (which would hold Fragment B inside it) can be started after clicking something in Fragment A.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是我的(选项卡+片段+ViewPager)解决方案,它对我有用,正如我想要的那样,
希望这对你也有用,
这是 xml 文件
这是 MainActivity.java 的代码,我只会发布相关代码,以便您必须管理它
这是我处理细节片段的方法,虽然不是很有效,但有点工作
不要将选项卡的状态保存在其单独的片段中,这会发生冲突,我们已经在这里这样做了
Here is my solution for the (Tabs + Fragment + ViewPager) it is works for me as i wanted,
hope that works for you as well
here is the xml file
here is the code for MainActivity.java I'll post relevant code only so you'll have to manage it
and here is how i deal with detail fragment not very efficient but kind of working
do not save the state of tab in their individual fragment it will conflict, we are already doing it here
编辑:
欢呼得太早了。现在,details_container 不是 viewpager,我无法使用它来“滑动选项卡”。
找到了!只需定义两个 FrameLayout,第一个是 ViewPager,第二个是可以“加载”详细信息片段。这是通过动态添加片段并替换它们来完成的。
首先是两个 FrameLayout:
然后动态替换一个片段:
非常简单,我不明白为什么我花了几个小时才弄清楚这一点。
EDIT:
Cheered too soon. Now the details_container is not a viewpager and I cannot use it to 'swipe tabs'.
Found it! Just had to define two FrameLayouts, with in the first one the ViewPager and in the second the details fragments can be 'loaded'. This is done by adding fragments dynamically and replace them.
First the two FrameLayouts:
Then replace a fragment dynamically:
Very simple and I don't understand why it took me hours to figure this out..
我仍然没有找到一种可能性,可以有一个分页器容器,其中应该加载片段并保留(ActionBar)选项卡。然而,我找到了一个非常肮脏的解决方案来完成此任务,开始 intens(带有选项卡的主要活动)并在后退按钮不再需要它时完成前面的活动。
我改编了 ABS:支持演示 - 选项卡和寻呼机的代码。但它又真的很脏:
Tab2
ActionBarTabsPager 下的 LoaderCursorSupport.CursorLoaderListFragment (带有选项卡的主要活动)
在这个类中有一个 TabsAdapter
这可以做得更简单吗?或者我应该放弃将选项卡与片段历史记录一起使用?这是在Android 3.0之前通过ActivityGroups和Activities完成的,但似乎这不能用fragment来完成。
I still did not find a possibility to have a Pager container where fragments should be loaded in and also keep the (ActionBar) Tabs. I have however found a really dirty solution to acomplish this, with starting intens (Main Activity with the Tabs) and finishing the previous ones when the backbutton doesn't need it anymore.
I adapted the code from ABS: Support Demos - Tabs and Pager. But again it's really dirty:
LoaderCursorSupport.CursorLoaderListFragment under Tab2
ActionBarTabsPager (Main Activity with Tabs)
Inside this Class there's a TabsAdapter
Can this be done simpler? Or should I just give up on having Tabs together with fragment history? This was done before Android 3.0 with ActivityGroups and Activities, but it seems this can't be done with fragments.
我在听中发现了相同实现的另一个很好的例子... https://github.com/UweTrottmann/SeriesGuide< /a>
在此示例中,在 com.battlelancer.seriesguide.ui 包下,
您可以找到 UpcomingRecentActivity.java、UpcomingFragment.java
和布局comingdown_multipan.xml
这个示例对我有用...
我在添加时遇到了一个问题不同选项卡的详细片段的内容不同,它给了我类转换异常,
因此我实现了一个通用的 detalFragment 类并在 onCreateView 方法中创建了单独的布局,
但我发现的唯一一个问题是布局在选项卡切换时没有改变,可能是需要通过实现一些监听器来做到这一点,
当我找到答案时我会告诉你。
I found the other good example of the same implementation in hear... https://github.com/UweTrottmann/SeriesGuide
In this example under package com.battlelancer.seriesguide.ui
you can find UpcomingRecentActivity.java, and UpcomingFragment.java
and layout upcoming_multipan.xml
this example works for me...
I got one problem while adding different content for detail-fragment the different tabs, it gives me class-cast-exception
so i implemented a common detalFragment class and created separate layout in onCreateView method
but the only one problem i found is layout is not changing on tab switched, may be need to do it by implementing some listener
I'll tell you when i found the answer.