title: FragmentTabHosts-Tab content is added on every click on the tab
body: <p>I have a FragmentTabHost with 4 tabs. The content of one tab is created dynamically in the <code>onViewCreated</code> method. It's a table and the amount of rows added to this table depends on the user settings.</p>
  
  <p>My problem is, when I add (for testing purposes) 3 rows to the table, switch the tab and switch back, I have 6 rows in the table. If I do it again, I have 9 rows in the table.</p>
  
  <p>So everytime I open this tab 3 rows are added to the table without the former content being deleted.</p>
  
  <p>If I got it right, the FragmentTabHost stores the state of each Tabs Fragment. So I check if the <code>savedInstanceState</code> of the <code>onViewCreated</code> method is null before adding the rows. Unfortunately <code>savedInstanceState</code> always returns null.</p>
  
  <p>This is the initialization code of my FragmentTabHost</p>
  
  <pre><code>private void initTabs()
  {
      FragmentTabHost tabHost = (FragmentTabHost)findViewById(android.R.id.tabhost);
  
      tabHost.setup(this, getSupportFragmentManager(),R.id.realtabcontent);
      tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("tab1"), TestFragment1.class, null);
      tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("tab2"), TestFragment2.class, null);
      tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator("tab3"), TestFragment3.class, null);
      tabHost.addTab(tabHost.newTabSpec("tab4").setIndicator("tab4"), TestFragment4.class, null);     
  
      tabHost.setOnTabChangedListener(this);
  }
  </code></pre>
  
  <p>This is the code of the 'tableView'-Fragment of one of the tabs:</p>
  
  <pre><code>@Override 
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) 
  {
      super.onCreateView(inflater, container, savedInstanceState);
      return inflater.inflate(R.layout.tab_tableview, container, false);    
  }
  
  @Override
  public void onViewCreated(View view, Bundle savedInstanceState) 
  {
      super.onViewCreated(view, savedInstanceState);
  
      Log.d("savedInstanceState", String.valueOf(savedInstanceState)); // is always null
  
      if (savedInstanceState != null)
          return;
  
      // Add Test-Rows
      for (int i=0; i&lt;3; i++)
      {
          RowFragment fragment = new RowFragment();
          FragmentTransaction ft = getChildFragmentManager().beginTransaction();
          ft.add(R.id.RowFragmentLayoutContainer, fragment);
          ft.commit();
      }
  </code></pre>
  
  <p>}</p>
  
  <p>What is wrong with my code? What must I do to only add the rows once?</p>