0

I'm trying to develop a tab based application. Each tab has its fragment. One of them has ViewPager, and ViewPager has its own pages. I move from to another by scrolling in this viewpager.

When I open the application for the first time, there is no problem. However, when I move from this tab, and come to it again, it does not show viewpager content, it does not fire FragmentPagerAdapter class.

Tab A - Tab B - Tab C

Tab C Fragment has ViewPage.

ViewPage has its own pages.

public class FragmentC extends Fragment {

public static final String ARG_SECTION_NUMBER = "section_number";
 static ViewPager C_mViewPager; 
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {


    C_mViewPager = (ViewPager)inflater.inflate(R.layout.fragmentC, container,false);
             C_SectionsPagerAdapter mC_PagerAdapter=new C_SectionsPagerAdapter(MainActivity.fragmentManagerv4);
             C_mViewPager.setAdapter(mC_PagerAdapter);


 return C_mViewPager;

}
public class C_SectionsPagerAdapter extends FragmentPagerAdapter {


    public C_SectionsPagerAdapter (FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int i) {
        Fragment fragment = null ;
         Bundle args;
        switch (i) {
        case 0:

            fragment=new A_SubFragment();
            break;

        case 1:

            fragment = new B_SubFragment();
            break;

        case 2:

        fragment = new C_SubFragment();
        break;

        case 3:

        fragment = new D_SubFragment();
        break;



}
        return fragment;
    }

    @Override
    public int getCount() {
        return 4;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        switch (position) {
            case 0: return getString(R.string.title_section1).toUpperCase();
            case 1: return getString(R.string.title_section2).toUpperCase();
            case 2: return getString(R.string.title_section3).toUpperCase();
            case 3: return getString(R.string.title_section4).toUpperCase();

        }
        return null;
    }
}
public static class A_SubFragment extends Fragment {


    public A_SubFragment() {
    }

    public static final String ARG_SECTION_NUMBER = "section_number";

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        RelativeLayout theLayout=(RelativeLayout)inflater.inflate(R.layout.a_sub_fragment, container,false);
//...
 return theLayout;}}
} 

Fragment C;

<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" />
Ravi
  • 34,851
  • 21
  • 122
  • 183
essbek
  • 59
  • 1
  • 3
  • 10

1 Answers1

0

I got the answer, I used FragmentStatePagerAdapter Instead of FragmentPagerAdapter

essbek
  • 59
  • 1
  • 3
  • 10