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


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)