如何使用标签ViewPagers? [英] How to use ViewPagers in Tabs?

查看:288
本文介绍了如何使用标签ViewPagers?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想添加一个ViewPager为每个标签来显示图像。有关推出的第一个标签,一切都很好。这些片段都被提取自定义FragmentStatePagerAdapter的帮助。我在实例方法CreateTabContent一个新的ViewPager对象。

I'm trying to add a ViewPager for each tab to display images. For the first tab on the launch, everything is fine. The Fragments are being fetched with the help of custom FragmentStatePagerAdapter. I'm instantiating a new ViewPager object in CreateTabContent method.

当我点击选项卡2显示第一个选项卡的内容后,将出现问题。我新ViewPager对象上设置一个新的FragmentStatePagerAdapter对象。同样都喜欢getCount将,的getItem,getItemPosition方法正确执行,但对象是不重视的ViewPager。

The problem occurs when I click on Tab 2, after the contents of first tab are displayed. I set a new FragmentStatePagerAdapter object on the new ViewPager object. Again all the methods like getCount, getItem, getItemPosition execute properly, but the objects are do not attach to the ViewPager.

在检查hierarchviewer,我发现没有被创建NoSaveStateFrameLayout对象。

On checking the hierarchviewer, I found out that NoSaveStateFrameLayout objects are not being created.

感谢。

请注意:我已经实现notifyDataSetChanged。

Note: I've implemented notifyDataSetChanged.

发生该问题

推荐答案

我找到了解决办法。我检查hierarchyviewer,再次仔细并且发现了NoSaveStateFrameLayout对象,它应该被连接到ViewPager为下一个标签被附着到第一ViewPager。所以,我超脱于标签1 ViewPager使用这种code点击下一个标签时:

I found out the solution. I checked the hierarchyviewer, again, carefully and found out that NoSaveStateFrameLayout object, which should be attached to the ViewPager for the next tab was being attached to the first ViewPager. So, I detached the ViewPager on tab 1 when next tab is clicked using this code:

FrameLayout frameLayout  = mTabHost.getTabContentView();
frameLayout.removeViewAt(index);

现在,只有一个ViewPager对象存在,一切是伟大的工作。

Now, Only one ViewPager object exists and everything is working great.

这篇关于如何使用标签ViewPagers?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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