0

Add the fragments and start the pager adapter to display each fragment.

 private void slide() {
        List<Fragment> fragments = new Vector<Fragment>() ;
        fragments.add(Fragment.instantiate(getActivity(), imageone.class.getName())) ;
        fragments.add(Fragment.instantiate(getActivity(),imagetwo.class.getName())) ;
        fragments.add(Fragment.instantiate(getActivity(), imagethree.class.getName())) ;
        mPagerAdapter =new pager(getActivity().getSupportFragmentManager(), fragments) ;
        pager.setAdapter(mPagerAdapter) ;
    }

The problem I have is that is only showing the first fragment and when I swipe to change the fragment doesn't change it. It works with my other app that isn't extending to FRAGMENT. The other app extends to FragmentActivity

public class MainActivity extends FragmentActivity {
... 
...
}

How do I set this to work Fragment inside fragmenst. I'm getting no errors but I'm unable to slide between views. The pager adapter that I'm using is this:

public class pager extends FragmentPagerAdapter {
    private List<Fragment> fragments ;
    public pager(FragmentManager fm, List<Fragment> fragments) {
        super(fm);
        this.fragments = fragments;
    }
    public Fragment getItem(int arg0) {
        return this.fragments.get(arg0);
    }
    public int getCount() {
        return this.fragments.size();
    }

}

1 Answers1

0

Replace getActivity().getSupportFragmentManager() with getChildFragmentManager()

See https://stackoverflow.com/a/35919170/1257369 https://stackoverflow.com/a/25525714/1257369

Community
  • 1
  • 1
everyman
  • 3,377
  • 1
  • 34
  • 33