title: ViewPager + FragmentStatePagerAdapter not working as intended
body: <p>There are a lot of similar question but none of them solved my problem.</p>
  
  <p>I got nested <code>ViewPager</code>s and nested <code>FragmentStatePagerAdapter</code>s in my application.</p>
  
  <p>In details, a first ViewPager (backed with a 4 fragments adapter) is created, the first fragment of which contains other 3 fragments.</p>
  
  <p>My problem is that, based on some events, the middle Fragment is not showing at all.</p>
  
  <p>As soon as the app is started, everything works as intended and is showing correctly.</p>
  
  <p>If I switch page on the parent ViewPager, the behavior is different based on the page: if I go from the first (which contains the nested ViewPager) to the second and then back to the first, still everything works as expected; If I go to any other page and then back to the first one, at first the ViewPager goes fully transparent but is still swipeable. In order to make the view get redrawed on the screen I have to swipe a couple of times from 1st to 3rd page, but no matter what, the 2nd Fragment is not showing. It is fully trasparent.</p>
  
  <p>I've already read a lots of similar question, but couldn't find any working fix.
  I'm very confused at the moment, I've tried everything.</p>
  
  <p>Here's my code for reference:</p>
  
  <p><strong>Parent Activity:</strong></p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(...);
  
      mCoordinatorLayout = (CoordinatorLayout) findViewById(R.id.feed_coordinator);
      mFloatingActionButton = (FloatingActionButton) findViewById(R.id.feed_floating_upload);
      mViewPager = (ViewPager) findViewById(R.id.feed_view_pager);
      mTabLayout = (TabLayout) findViewById(R.id.feed_tab_layout);
  
      setupViewPager(); // this sets adapter to viewpager
      mTabLayout.setupWithViewPager(mViewPager);
      setupTabLayout();
  
  }
  
  private class ParentPagerAdapter extends FragmentStatePagerAdapter {
      public ParentPagerAdapter(FragmentManager fm) {
          super(fm);
      }
      @Override
      public Fragment getItem(int position) {
          switch (position) {
              case 0:
                  return new Frag1();
              case 1:
                  return new Frag2();
              case 2:
                  return new Frag3();
              case 3:
                  return new Frag4();
              default:
                  return new Default();
          }
      }
      @Override
      public int getCount() {
          return 4;
      }
  }
  </code></pre>
  
  <p><strong>Frag1</strong> is pretty much similar:</p>
  
  <pre><code>public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
  
      View view = inflater.inflate(R.layout.frag1, container, false);
  
      [...]
  
      mViewPager = (ViewPager) view.findViewById(R.id....);
      mLinearLayout = (LinearLayout) view.findViewById(R.id....);
  
      mFragmentAdapter = new MyFragmentAdapter(getFragmentManager());
      mViewPager.setAdapter(mFragmentAdapter);
      return view;
  }
  
  private class MyFragmentAdapter extends FragmentStatePagerAdapter {
      private static final int ITEMS = 3;
      public MyFragmentAdapter(FragmentManager fm) {
          super(fm);
      }
      @Override
      public Fragment getItem(int position) {
          switch (position) {
              case 0:
                  new Child1();
              case 1:
                  new Child2();
              case 2:
                  new Child3();
              default:
                  return null;
          }
      }
      @Override
      public int getCount() {
          return ITEMS;
      }
  }
  </code></pre>
  
  <p>The 3 childs follow a very simple implementation, they fetch data from server and show them in a RecyclerView. If needed I will post the class too.</p>
  
  <p>I really don't know what to do, nothing seems to work.
  Any kind of help would be really appreciated, thanks!</p>