getChildFragmentManager() 方法未定义

2023-10-04移动开发问题
1

本文介绍了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() 方法未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

使用 cocos2d 处理对 CCSprite 的触摸的最佳实践
Best practices for handling touches to a CCSprite with cocos2d(使用 cocos2d 处理对 CCSprite 的触摸的最佳实践)...
2024-08-12 移动开发问题
3

UIActivityViewControllerCompletionHandler 怎么做?
UIActivityViewControllerCompletionHandler How to?(UIActivityViewControllerCompletionHandler 怎么做?)...
2024-08-12 移动开发问题
4

如何暂停和恢复应用于 ccSprite 的操作?
how to pause and resume action applied to the ccSprite?(如何暂停和恢复应用于 ccSprite 的操作?)...
2024-08-12 移动开发问题
4

如何在 COCOS2d Android 中使用 CClistview?
How can I use CClistview in COCOS2d Android?(如何在 COCOS2d Android 中使用 CClistview?)...
2024-08-12 移动开发问题
5

cocos2d-android:如何显示分数
cocos2d-android: how to display score(cocos2d-android:如何显示分数)...
2024-08-11 移动开发问题
7

重用 cocos2d 动作
Reuse cocos2d actions(重用 cocos2d 动作)...
2024-08-11 移动开发问题
4