title: Android fragment nested in another fragment: getParentFragment() returns 0
body: <p>Basically the situation is like this: I have an <code>Activity</code>, which displays a three <code>Fragments</code> within a <code>FragmentPagerAdapter</code>, and within one of these <code>Fragment</code>, I nest another <code>Fragment</code>. I added the fragments like this:</p>
  <pre><code>fragmentTransaction = getFragmentManager().beginTransaction();
  fragmentTransaction.add(rootView.getId(), new MainPageFragment(), &quot;lpt2&quot;);
  fragmentTransaction.commit();
  </code></pre>
  <p>When I try to call <code>getParentFragment()</code> inside of <code>MainPageFragment()</code>, it returns <code>null</code>.
  How can that be? I checked multiple posts here on stackoverflow as well as on other blogs, and they all came to the conclusion that if you nest one fragment within another one, calling <code>getParentFragment</code> should return its parent fragment. Returning <code>null</code> means, that the parent is an activity as stated <a href="http://developer.android.com/reference/android/app/Fragment.html#getParentFragment%28%29" rel="nofollow noreferrer">here</a>. Which is not the case. Please tell me I'm making some kind of silly mistakes :\</p>
  <p>This is the <code>Fragment</code> that is a child to the main <code>Activity</code></p>
  <pre><code>public class MainPage extends Fragment {
  
  private FragmentTransaction fragmentTransaction;
  private View rootView;
  
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
             Bundle savedInstanceState) {
          global_var = new Global();
          rootView = inflater.inflate(R.layout.main_page, container, false);
          return rootView;
  }
  @Override
  public void onViewCreated (View view, Bundle savedInstanceState) {      
      fragmentTransaction = getFragmentManager().beginTransaction();
      fragmentTransaction.add(rootView.getId(), new MainPageFragment(), &quot;lpt2&quot;);
      fragmentTransaction.commit();
  }
  }
  </code></pre>
  <p>This is the Fragment which is a child to the <code>Main Page Fragment</code></p>
  <pre><code>public class MainPageFragment extends Fragment{
  private View rootView;
  private Fragment parentFragment;
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      rootView = inflater.inflate(R.layout.main_page_list, container, false);
      if (getParentFragment() == null) Log.i(&quot;damn&quot;, &quot;it&quot;);
      return rootView;
     }
  
  @Override
  public void onViewCreated(View view, Bundle savedInstanceState) {
      // TODO Auto-generated method stub
      super.onViewCreated(view, savedInstanceState);
  }
  }
  </code></pre>
  <p>Please tell me if I need to provide more code, I extracted things like <code>ListView</code> and so on because I thought it would be irrelevant.</p>
  <p>Edit: I'm using android.support.v4.app</p>