问题
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:
The method getChildFragmentManager() is undefined for the type ViewPagerActivity
This is my 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();
}
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.
I'm doing this because I need to have a ListFragment inside a Fragment that I use like a page on my ViewPager.
回答1:
getChildFragmentManager()
is a method on Fragment
, not on FragmentActivity
. Use getSupportFragmentManager()
on a FragmentActivity
.
来源:https://stackoverflow.com/questions/16945904/the-method-getchildfragmentmanager-is-undefined