getChildFragmentManager() 方法未定义 [英] The method getChildFragmentManager() is undefined

查看:33
本文介绍了getChildFragmentManager() 方法未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 SherlockFragmentActivity,这个 Activity 有一个 SectionsPagerAdapter 和一个 ViewPager.当我使用 getChildFragmentManager() 方法调用 SectionsPagerAdapter 的构造函数时,它会显示以下错误消息:

I have a SherlockFragmentActivity, this Activity have a SectionsPagerAdapter and a ViewPager. When I call the constructor of the SectionsPagerAdapter with getChildFragmentManager() method, it shows me this error message:

方法 getChildFragmentManager() 未定义 ViewPagerActivity 类型

The method getChildFragmentManager() is undefined for the type ViewPagerActivity

这是我的代码:

public class ViewPagerActivity extends SherlockFragmentActivity implements OnPageChangeListener, OnQueryTextListener{

private SectionsPagerAdapter sectionsPagerAdapter;
private ViewPager viewPager;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.layout_view_pager);

    sectionsPagerAdapter = new SectionsPagerAdapter(getChildFragmentManager(), this);

    viewPager = (ViewPager) findViewById(R.id.pager);
    viewPager.setAdapter(sectionsPagerAdapter);
    viewPager.setOnPageChangeListener(this);

    this.getMovements();

    this.getPrizes();

    this.getVouchers();

    this.createDropdownlist(); 
}

我正在使用 ActionBarSherlock,并在我的项目中使用 Android 工具 - 添加支持库" 更新了 android-support-v4.jar,也在 ActionBarSherlock 项目中.

I'm using ActionBarSherlock and I updated the android-support-v4.jar using "Android Tools - Add Support Library" in my project, also on ActionBarSherlock project.

我这样做是因为我需要在 Fragment 中有一个 ListFragment,我像 ViewPager 上的页面一样使用它.

I'm doing this because I need to have a ListFragment inside a Fragment that I use like a page on my ViewPager.

推荐答案

getChildFragmentManager()Fragment 上的方法,而不是 FragmentActivity 上的方法.在 FragmentActivity 上使用 getSupportFragmentManager().

getChildFragmentManager() is a method on Fragment, not on FragmentActivity. Use getSupportFragmentManager() on a FragmentActivity.

这篇关于getChildFragmentManager() 方法未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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