title: Check if fragment exists on Framelayout
body: <p>I'm using ViewPager with 3 fragments in my project. One of these 3 fragments must contain another fragment inside of it, for what I have defined a FrameLayout in fragment's layout:</p>
  
  <pre><code>&lt;RelativeLayout 
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent" &gt;
  
      &lt;LinearLayout
          android:id="@+id/valuesContainer"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_marginTop="20dp" &gt;
  
          ...        
      &lt;/LinearLayout&gt;
  
      &lt;FrameLayout
          android:id="@+id/model3d_container"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:layout_below="@+id/valuesContainer"
          android:layout_centerHorizontal="true"
          android:layout_margin="15dp"
          android:layout_marginTop="20dp" /&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Now I add the new fragment programmatically:</p>
  
  <pre><code>@Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          View view = inflater.inflate(R.layout.layout_row3d, container, false);
  
          /*Check if fragment is already loaded*/
          Fragment frag = getActivity().getSupportFragmentManager().findFragmentById(R.id.model3d_container);
          if (frag == null) {
              /*load fragment with 3d model*/
              Fragment modelFragment = new Obj3DView();
              FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
              transaction.add(R.id.model3d_container, modelFragment).commit();
          }
          return view;
      }
  </code></pre>
  
  <p>But when I navigate through the ViewPager's view, when I return to the fragment which contains the child fragment, the app crashes. Reading the Log, it seems that has something to do with the child fragment loading. I have defined a method to check if the fragment is loaded, and if so, not to load, but I think that is is reloading anyway.</p>
  
  <pre><code>10-13 12:48:34.809: E/AndroidRuntime(26460): FATAL EXCEPTION: main
  10-13 12:48:34.809: E/AndroidRuntime(26460): Process: com.rowingsoft, PID: 26460
  10-13 12:48:34.809: E/AndroidRuntime(26460): java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
  10-13 12:48:34.809: E/AndroidRuntime(26460):    at android.view.ViewGroup.addViewInner(ViewGroup.java:3759)
  10-13 12:48:34.809: E/AndroidRuntime(26460):    at android.view.ViewGroup.addView(ViewGroup.java:3612)
  10-13 12:48:34.809: E/AndroidRuntime(26460):    at android.view.ViewGroup.addView(ViewGroup.java:3557)
  10-13 12:48:34.809: E/AndroidRuntime(26460):    at android.view.ViewGroup.addView(ViewGroup.java:3533)
  10-13 12:48:34.809: E/AndroidRuntime(26460):    at android.support.v4.app.NoSaveStateFrameLayout.wrap(NoSaveStateFrameLayout.java:40)
  10-13 12:48:34.809: E/AndroidRuntime(26460):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:931)
  10-13 12:48:34.809: E/AndroidRuntime(26460):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
  10-13 12:48:34.809: E/AndroidRuntime(26460):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1086)
  10-13 12:48:34.809: E/AndroidRuntime(26460):    at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1884)
  10-13 12:48:34.809: E/AndroidRuntime(26460):    at android.support.v4.app.Fragment.performActivityCreated(Fragment.java:1514)
  10-13 12:48:34.809: E/AndroidRuntime(26460):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:947)
  10-13 12:48:34.809: E/AndroidRuntime(26460):    at android.support.v4.app.FragmentManagerImpl.attachFragment(FragmentManager.java:1280)
  10-13 12:48:34.809: E/AndroidRuntime(26460):    at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:672)
  10-13 12:48:34.809: E/AndroidRuntime(26460):    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
  10-13 12:48:34.809: E/AndroidRuntime(26460):    at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:472)
  10-13 12:48:34.809: E/AndroidRuntime(26460):    at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
  10-13 12:48:34.809: E/AndroidRuntime(26460):    at android.support.v4.view.ViewPager.populate(ViewPager.java:1068)
  10-13 12:48:34.809: E/AndroidRuntime(26460):    at android.support.v4.view.ViewPager.populate(ViewPager.java:914)
  10-13 12:48:34.809: E/AndroidRuntime(26460):    at android.support.v4.view.ViewPager$3.run(ViewPager.java:244)
  10-13 12:48:34.809: E/AndroidRuntime(26460):    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:803)
  10-13 12:48:34.809: E/AndroidRuntime(26460):    at android.view.Choreographer.doCallbacks(Choreographer.java:603)
  10-13 12:48:34.809: E/AndroidRuntime(26460):    at android.view.Choreographer.doFrame(Choreographer.java:572)
  10-13 12:48:34.809: E/AndroidRuntime(26460):    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:789)
  10-13 12:48:34.809: E/AndroidRuntime(26460):    at android.os.Handler.handleCallback(Handler.java:733)
  10-13 12:48:34.809: E/AndroidRuntime(26460):    at android.os.Handler.dispatchMessage(Handler.java:95)
  10-13 12:48:34.809: E/AndroidRuntime(26460):    at android.os.Looper.loop(Looper.java:157)
  10-13 12:48:34.809: E/AndroidRuntime(26460):    at android.app.ActivityThread.main(ActivityThread.java:5356)
  10-13 12:48:34.809: E/AndroidRuntime(26460):    at java.lang.reflect.Method.invokeNative(Native Method)
  10-13 12:48:34.809: E/AndroidRuntime(26460):    at java.lang.reflect.Method.invoke(Method.java:515)
  10-13 12:48:34.809: E/AndroidRuntime(26460):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
  10-13 12:48:34.809: E/AndroidRuntime(26460):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
  10-13 12:48:34.809: E/AndroidRuntime(26460):    at dalvik.system.NativeStart.main(Native Method)
  </code></pre>