title: Display fragment viewpager within a fragment
body: <p>I have a fragment which contains a ViewPager.  The ViewPager is associated with an adapter that contains a set of fragments.</p>
  
  <p>Upon loading the parent fragment, I am met with an <code>IllegalStateException</code> with the message: <code>java.lang.IllegalStateException: Recursive entry to executePendingTransactions</code>.</p>
  
  <p>Some research has led me to the conclusion that the system is unable display fragments within another fragment, HOWEVER there seems to be some indication that it is possible to do exactly this with the use of a ViewPager (<a href="https://stackoverflow.com/questions/7241153/a-bug-in-viewpager-using-it-with-other-fragment/7654881#7654881">A bug in ViewPager using it with other fragment</a>).</p>
  
  <p>In fact, if I add a button to my parent fragment which calls <code>mPager.setAdapter(mAdapter)</code> on my ViewPager when pressed, the ViewPager successfully loads.  This is not ideal.</p>
  
  <p>The issue then must be related to the fragment lifecycle.  My question therefore, is this:
  Has anybody else found a way around this issue, and if so, how?</p>
  
  <p>Is there some way to delay settings the adapter on the ViewPager until after the fragment transaction?</p>
  
  <p>Here is my parent fragment code:</p>
  
  <pre><code>    @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  
      mView = inflater.inflate(R.layout.team_card_master, container, false);
      mViewPager = (ViewPager)mView.findViewById(R.id.team_card_master_view_pager);
  
      final Button button = (Button)mView.findViewById(R.id.load_viewpager_button);
      button.setOnClickListener(new OnClickListener() {
          @Override
          public void onClick(View v) {
              mViewPager.setAdapter(mAdapter);
              button.setVisibility(View.GONE);
          }
      });
  
      mAdapter = new ViewPagerAdapter(getFragmentManager());
   //     mViewPager.setAdapter(mAdapter);
  
      return mView;
  }
  </code></pre>
  
  <p>And the adapter:</p>
  
  <pre><code>public class ViewPagerAdapter extends FragmentPagerAdapter {
      public ViewPagerAdapter(FragmentManager fm) {
          super(fm);
      }
  
      @Override
      public int getCount() {
          if (mCursor == null) return 0;
          else return mCursor.getCount();
      }
  
      @Override
      public Fragment getItem(int position) {
          Bundle b = createBundle(position, mCursor);
          return TeamCardFragment.newInstance(b);
      }
  }
  </code></pre>