I have a viewpager inside fragment. I would like to use FragmentPagerAdapter to swipe between fragments inside my viewpager.
public static class MyFragmentPagerAdapter extends FragmentPagerAdapter {
public MyFragmentPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int index) {
return new ResponderInputFragment();
}
@Override
public int getCount() {
return 1;
}
}
I create this adapter like this:
viewPager = (ViewPager) v.findViewById(R.id.pager);
mMyFragmentPagerAdapter = new MyFragmentPagerAdapter(getChildFragmentManager());
viewPager.setAdapter(mMyFragmentPagerAdapter);
ResponderInputFragment (currently my single fragment inside my viewpager)'s methods like onCreateView and onCreate are called, but nothing appears on screen where viewpager should be (also no errors in logcat).
Layout for FragmentActivity that hosts my fragment:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#D2D9DB"
android:orientation="vertical" >
<View
android:layout_width="match_parent"
android:layout_height="3dip"
android:background="@drawable/laser_background"
/>
<FrameLayout
android:id="@+id/responder_fragment_container"
android:layout_width="match_parent"
android:layout_margin="10dip"
android:layout_height="match_parent" >
</FrameLayout>
</LinearLayout>
I put my fragment into containter like this:
android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager();
android.support.v4.app.FragmentTransaction ft = fragmentManager.beginTransaction();
ft.replace(R.id.responder_fragment_container, new ResponderMultipleFragment());
ft.commit();