title: Fragment added programmatically disappear
body: <p>My application uses tabs, each tab is <code>Fragment</code> (from android.app.Fragment). I want to use nested fragments in one of those.</p>
  
  <p>Here is the top level fragment supposed to contains the nested fragment:</p>
  
  <pre><code>import android.app.Fragment;
  import android.os.Bundle;
  import android.support.v4.app.FragmentActivity;
  import android.support.v4.app.FragmentManager;
  import android.support.v4.app.FragmentTransaction;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import fr.epitech.test_esi.R;
  
  public class ReservationCalendarFragment extends Fragment {
      public static final int stringId = R.string.calendar_tab;
      public static final String tag = "reservation_calendar_frag";
  
      CalendarFragment t = new CalendarFragment();
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          FragmentManager fm = ((FragmentActivity) getActivity())
                  .getSupportFragmentManager();
          FragmentTransaction ft = fm.beginTransaction();
          ft.add(R.id.calendarframelayout, t, CalendarFragment.tag);
          ft.commit();
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
          return inflater.inflate(R.layout.reservation_calendar_layout, null);
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>It adds programmatically the first fragment using a <code>FragmentTransaction</code>. It actually works (i mean, the nested fragment is added and i can see it) but each time i switch to another tab (so another fragment is displayed) and go back to it, the nested fragment has disappeared.</p>
  
  <p>Here is the code of the <code>CalendarFragment</code>:</p>
  
  <pre><code>import java.text.SimpleDateFormat;
  import java.util.Calendar;
  import java.util.Locale;
  
  import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.util.Log;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.CalendarView;
  import android.widget.CalendarView.OnDateChangeListener;
  import fr.epitech.test_esi.R;
  
  public class CalendarFragment extends Fragment {
  
      public static final String tag = "calendar_frag";
  
      private SimpleDateFormat _df = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
          View fragView = inflater.inflate(R.layout.calendar_layout, null);
          CalendarView calendarView = (CalendarView) fragView
                  .findViewById(R.id.calendar);
          calendarView.setOnDateChangeListener(new OnDateChangeListener() {
  
              @Override
              public void onSelectedDayChange(CalendarView view, int year,
                      int month, int dayOfMonth) {
                  Calendar c = Calendar.getInstance();
  
                  c.set(year, month, dayOfMonth);
                  Log.d("DATE", c.getTime().toString());
              }
          });
          return fragView;
      }
  </code></pre>
  
  <ul>
  <li>The nested fragment <code>CalendarFragment</code> extends <code>android.support.v4.app.Fragment</code></li>
  <li>My activity is a <code>FragmentActivity</code></li>
  </ul>
  
  <p>I even tried stay on this fragment, put the activity in background (using home button) and resume it, the nested fragment is still displayed. It's really happen when i switch between the tabs of my application.</p>