Android的viewpager在片段 [英] Android viewpager in fragment

查看:294
本文介绍了Android的viewpager在片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尊敬的女士们和男士,

首先,请不要记住我的问题了。如果你认为我的问题是太傻了,请让我知道,我会修改或删除。

First of all, please do not mark my question down. If you think that my question is too stupid please let me know and i will edit it or remove.

所以我实际的问题是,我有一个活动(延伸活动)。在该活动的布局,我创建的FrameLayout 在这里我再附上不同的4个片段(所以每个延伸片段的。因此,在中的一个片段,我想实现滑动式标签(见截图)。

So my actual question is that I have an activity (extends Activity). In that activity's layout I created FrameLayout where I then attach different four fragments(so each of them extends Fragment. So in one of that fragments I would like to implements swipeable tabs(see screenshot).

我知道,它通常是通过实施viewPager和FragmentPagerAdapter做的,但我不能这样做,如果我打电话 getSupportFragmentManager 在我的片段,它给我的一个错误。如果我使用 getActivity()。getFragmentManager()它给了我, android.support.v4.app.fragmentmanager不能应用于android.app.fragmentmanager错误。我在我的片段使用android.support.v4.app.fragment,否则我将无法实现我的活动的观点(在beggining描述)。

I know that it is usually done by implementing viewPager and FragmentPagerAdapter, but I can not do this as if I'm calling getSupportFragmentManager in my fragment it gives my an error. If i am using getActivity().getFragmentManager() it gives me error that android.support.v4.app.fragmentmanager cannot be applied to android.app.fragmentmanager. I have to use android.support.v4.app.fragment in my fragment, because otherwise I will not be able to implement my activity's view(described at the beggining).

任何意见或建议将是非常美联社preciated。截图

Any ideas or suggestions would be very appreciated.screenshot

推荐答案

请确保您使用的是您扩展您的片段来自支持库片段类。你还需要使用 FragmentActivity 来调用方法 getSupportFragmentManager();

Make sure you are using Fragment class that you extends your fragments comes from support library. You also need to use FragmentActivity to call method getSupportFragmentManager();

在另一方面, viewpager 这是您的片段需要像往常一样,你可以找到互联网上实现除 getChildSupportFragmentManager();

On the other hand, viewpager which is in your fragment need to implemented as usual that you can find on internet except getChildSupportFragmentManager();

这一个叫嵌套的碎片。

PS:我不知道,但你也可以使用 AppCompatActivity 而不是 FragmentActivity 的。 FragmentActivity ActionBarActivity 必须的德precated

PS: I am not sure but you can also use AppCompatActivity instead of FragmentActivity. FragmentActivity and ActionBarActivity must be deprecated.

好运气

这篇关于Android的viewpager在片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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