Home > Mobile >  Combined FragmentPagerAdapter and viewpager why can only display the last fragments page?
Combined FragmentPagerAdapter and viewpager why can only display the last fragments page?

Time:09-22

 private List the  fragmentList=new ArrayList  (); FragmentList. Add (new TFM2 ()); 
FragmentList. Add (new TFM1 ());
FragmentList. Add (new TFM2 ());
FragmentList. Add (new TFM2 ());
FragmentList. Add (new TFM2 ());
FragmentList. Add (new TFM2 ());
FragmentList. Add (new TFM2 ());
Viewpager. SetOffscreenPageLimit (fragmentList. The size ());
MyAdapter MyAdapter=new MyAdapter (getSupportFragmentManager ());
Viewpager. SetAdapter (myAdapter);
TabLayout. SetupWithViewPager (viewpager);

Public class MyAdapter extends FragmentPagerAdapter {

Public MyAdapter (@ NonNull FragmentManager FM) {
Super (FM);
}

@ NonNull
@ Override
Public fragments the getItem (int position) {
return fragmentList.get(position);
}

@ Override
Public int getCount () {

Return fragmentList. The size ();
}

@ Nullable
@ Override
Public CharSequence getPageTitle (int position) {
The e (" getPageTitle getPageTitle ", ":" + strings [position]);
Return strings [position];
}
}
  • Related