该方法getChildFragmentManager()是未定义 [英] The method getChildFragmentManager() is undefined
问题描述
我有一个SherlockFragmentActivity,这个活动有一个SectionsPagerAdapter和ViewPager。当我打电话SectionsPagerAdapter的构造与 getChildFragmentManager()
方法,它显示我此错误消息:
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
这是我的code:
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的支持 - v4.jar。Android的工具 - 添加支持库的在我的项目,也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.
我这样做,因为我需要的,我喜欢用一个页面上我ViewPager一个片段内ListFragment。
I'm doing this because I need to have a ListFragment inside a Fragment that I use like a page on my ViewPager.
推荐答案
getChildFragmentManager()
是片段的方法
,而不是 FragmentActivity
。使用 getSupportFragmentManager()
在 FragmentActivity
。
getChildFragmentManager()
is a method on Fragment
, not on FragmentActivity
. Use getSupportFragmentManager()
on a FragmentActivity
.
这篇关于该方法getChildFragmentManager()是未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!