Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The method getChildFragmentManager() is undefined

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.

like image 793
Mark Comix Avatar asked Jun 05 '13 17:06

Mark Comix


1 Answers

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

like image 114
CommonsWare Avatar answered Nov 04 '22 11:11

CommonsWare