title: Where to call getChildFragmentManager()?
body: <h2>Problem</h2>
  
  <p>According to the Google's docs:</p>
  
  <blockquote>
    <p>You can now embed fragments inside fragments. This is useful for a
    variety of situations in which you want to place dynamic and re-usable
    UI components into a UI component that is itself dynamic and
    re-usable. For example, if you use ViewPager to create fragments that
    swipe left and right and consume a majority of the screen space, you
    can now insert fragments into each fragment page.
         To nest a fragment, simply call getChildFragmentManager() on the Fragment in which you want to add a fragment. This returns a
    FragmentManager that you can use like you normally do from the
    top-level activity to create fragment transactions. For example,
    here’s some code that adds a fragment from within an existing Fragment
    class:    </p>
  </blockquote>
  
  <pre><code>Fragment videoFragment = new VideoPlayerFragment();
  FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
  transaction.add(R.id.video_fragment, videoFragment).commit();
  </code></pre>
  
  <p>So I had (for example) <code>TestFragment</code> which looks like:</p>
  
  <pre><code>public class TestFragment extends Fragment {
  
      private View mFragmentView;
      private FrameLayout mFrameLayout;   
  
      public HistoryFragment() {
          super();
      }       
  
      @Override   
      public View onCreateView(LayoutInflater pInflater, ViewGroup pViewGroup, Bundle pBundle) {          
  
          mFragmentView = pInflater.inflate(R.layout.fragment_layout, pViewGroup, false);         
  
          mFrameLayout = (FrameLayout) mFragmentView.findViewById(R.id.framelayout);
  
          return mFragmentView;
      }   
  
      public void onDestroyView() {
          super.onDestroyView();
      }    
  
      /* ISSUE */
      public void doSomethingSpecial() {
          FragmentManager tFragmentManager = getChildFragmentManager();
      }
  }
  </code></pre>
  
  <p>At the <code>MainActivity</code> I initialize my fragment like:</p>
  
  <pre><code>mTestFragment = new TestFragment();
  mTestFragment.doSomethingSpecial();
  </code></pre>
  
  <p>Then I pass fragment to <code>ViewPager</code> via <code>FragmentPagerAdapter</code>. </p>
  
  <p>Finally, I get an exception. But if I use only:</p>
  
  <pre><code>mTestFragment = new TestFragment();
  </code></pre>
  
  <p>Then it works.</p>
  
  <h2>Question</h2>
  
  <p>Where should I call <code>getChildFragmentManager()</code> method in my fragment? What I am doing wrong?</p>
  
  <p><strong>If you have a good example of using new Android Nested Fragments please share link with me.</strong> I would greatly appreciate for your help.</p>