4

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();
Blo
  • 11,903
  • 5
  • 45
  • 99
DixieFlatline
  • 7,895
  • 24
  • 95
  • 147
  • What is there in your ResponderMultipleFragment class? Have you write ViewPager related things in that class? – Yashdeep Patel Jul 07 '13 at 08:44
  • FWIW, here is a sample app demonstrating a fragment holding onto a `ViewPager`, which itself uses child fragments in its pages: https://github.com/commonsguy/cw-omnibus/tree/master/ViewPager/Nested – CommonsWare Jul 07 '13 at 14:45
  • You should also post the layout file for the `ResponderMultipleFragment` fragment. – user Jul 07 '13 at 14:54

0 Answers0