title: Transaction between fragments only inside one ActionBar Tab
body: <p>I have an app with three tabs (ActionBar Tabs), each one with one fragment at a time.</p>
  
  <p>TabListener</p>
  
  <p>TabsActivity</p>
  
  <p>Tab1 -> ListFragment1 -> ListFragment2 -> Fragment3</p>
  
  <p>Tab2 -> Tab2Fragment</p>
  
  <p>Tab3 -> Tab3Fragment</p>
  
  <p>The problem is when I create the FragmentTransaction (inside OnListItemClicked) from ListFragment1 to ListFragment2, the fragments inside the other tabs also change to ListFragment2.</p>
  
  <p>In the end, I want to change fragments only inside on tab and preserve the state of the other tabs.</p>
  
  <p>I'm already saving the state (OnSavedInstance()).
  Do you know what I'm missing here?</p>
  
  <p>Some of the code:</p>
  
  <pre><code>public class TabsActivity extends Activity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.tabs);
  
          // setup Action Bar for tabs
          ActionBar actionBar = getActionBar();
          actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
  
          // instantiate fragment for the tab
          Fragment networksFragment = new NetworksFragment();
          // add a new tab and set its title text and tab listener
          actionBar.addTab(actionBar.newTab().setText("Tab1")
                  .setTabListener(new TabsListener(ListFragment1)));
  
          // instantiate fragment for the tab
          Fragment historyFragment = new HistoryFragment();
          // add a new tab and set its title text and tab listener
          actionBar.addTab(actionBar.newTab().setText("Tab2")
                  .setTabListener(new TabsListener(Tab2Fragment)));
  
          // instantiate fragment for the tab
          Fragment settingsFragment = new SettingsFragment();
          // add a new tab and set its title text and tab listener
          actionBar.addTab(actionBar.newTab().setText("Tab3")
                  .setTabListener(new TabsListener(Tab3Fragment)));
      }
  }
  </code></pre>
  
  <hr>
  
  <pre><code>public class TabsListener implements ActionBar.TabListener {
  
      private Fragment frag;
  
  
      // Called to create an instance of the listener when adding a new tab
      public TabsListener(Fragment networksFragment) {
          frag = networksFragment;
      }
  
      @Override
      public void onTabReselected(Tab arg0, FragmentTransaction arg1) {
          // TODO Auto-generated method stub
  
      }
  
      @Override
      public void onTabSelected(Tab tab, FragmentTransaction ft) {    
          ft.add(R.id.fragment_container, frag, null);
      }
  
      @Override
      public void onTabUnselected(Tab tab, FragmentTransaction ft) {
          ft.remove(frag);        
      }
  }
  </code></pre>
  
  <hr>
  
  <pre><code>public class ListFragment1 extends ListFragment {
  
      @Override
      public void onListItemClick(ListView l, View v, int position, long id) {
  
          getListView().setItemChecked(position, true);
  
          ListFragment2 fragment2 = ListFragment2.newInstance(position);
  
          FragmentTransaction ft = getFragmentManager().beginTransaction();
          ft.replace(R.id.fragment_container, fragment2);
          ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
          ft.addToBackStack(null);
          ft.commit();
      }
  }
  </code></pre>