title: ActionBar: Swipe between tabs
body: <p>I would like to make it possible to swipe between the tabs in my app.
  I have already found plenty tutorials to do this, but I can't get it to work with my code, because I use different code. 
  MyActivity.class:</p>
  
  <pre><code>public class MyActivity extends Activity {
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
  final ActionBar actionBar = getActionBar();
            actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
  
               ActionBar.Tab tabA = actionBar.newTab();
                  tabA.setIcon(R.drawable.icon_settings);
                actionBar.setDisplayShowHomeEnabled(false);
               actionBar.setDisplayShowTitleEnabled(false);
  
              tabA.setText("");
           tabA.setTabListener(new com.example.MainActivity.TabListener&lt;Tab1&gt;(this, "Tab1", Tab1.class));
           actionBar.addTab(tabA);
  
  
  
  
  
            Tab tabB = actionBar.newTab();
          tabB.setText("Tab2");
           tabB.setTabListener(new com.example.MainActivity.TabListener&lt;Tab2&gt;(this, "Tab2", Tab2.class));
            actionBar.addTab(tabB);
  
              Tab tabC = actionBar.newTab();           
              tabC.setText("Tab3");
  
           tabC.setTabListener(new com.example.MainActivity.TabListener&lt;Tab3&gt;(this, "Tab3", Tab3.class));
           actionBar.addTab(tabC);
  
          if (savedInstanceState != null) {
                int savedIndex = savedInstanceState.getInt("SAVED_INDEX");
              getActionBar().setSelectedNavigationItem(savedIndex);
         }
  }
  </code></pre>
  
  <p>Main.xml</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:orientation="vertical"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                 &gt;
      &lt;TabHost
              android:id="@+id/tabHost"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              &gt;
          &lt;LinearLayout
                  android:layout_width="fill_parent"
                  android:layout_height="fill_parent"
                  android:orientation="vertical"
                  android:paddingTop="5dip"&gt;
              &lt;TabWidget
                      android:id="@android:id/tabs"
                      android:layout_width="fill_parent"
                      android:layout_height="wrap_content"&gt;
              &lt;/TabWidget&gt;
              &lt;FrameLayout
                      android:id="@android:id/tabcontent"
                      android:layout_width="fill_parent"
                      android:layout_height="fill_parent"&gt;
  &lt;LinearLayout
                      android:id="@+id/einstellungen"
                      android:layout_width="fill_parent"
                      android:layout_height="wrap_content" android:orientation="vertical" android:background="#ffffff"&gt;
  &lt;/LinearLayout&gt;
              &lt;LinearLayout
                  android:id="@+id/tab1"
                  android:orientation="vertical"
                  android:layout_width="fill_parent"
                  android:layout_height="fill_parent"&gt;
             &lt;/LinearLayout&gt;
  
              &lt;LinearLayout
                      android:id="@+id/tab2"
                      android:orientation="vertical"
                      android:layout_width="fill_parent"
                      android:layout_height="fill_parent"&gt;
              &lt;/LinearLayout&gt;
              &lt;LinearLayout
                      android:id="@+id/tab3"
                      android:orientation="vertical"
                      android:layout_width="fill_parent"
                      android:layout_height="fill_parent"&gt;
              &lt;/LinearLayout&gt;
          &lt;/FrameLayout&gt;
      &lt;/LinearLayout&gt;
  &lt;/TabHost&gt;
  </code></pre>
  
  <p></p>
  
  <p>Tab1.class</p>
  
  <pre><code>public class Tab1 extends Fragment {
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      View myFragmentView = inflater.inflate(R.layout.fragment_a, container, false);
      return myFragmentView;
  }
  
  }
  </code></pre>
  
  <p>TabListener.class</p>
  
  <pre><code>public class TabListener &lt;T extends Fragment&gt; implements ActionBar.TabListener{
  
      private final Activity myActivity;
      private final String myTag;
      private final Class myClass;
  
      public TabListener(Activity activity, String tag, Class&lt;T&gt; cls) {
          myActivity = activity;
          myTag = tag;
          myClass = cls;
      }
      @Override
      public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
  
          Fragment myFragment = myActivity.getFragmentManager().findFragmentByTag(myTag);
  
          if (myFragment == null) {
              myFragment = Fragment.instantiate(myActivity, myClass.getName());
              ft.add(android.R.id.content, myFragment, myTag);
          } else {
              ft.attach(myFragment);
          }
  
      }
  
      @Override
      public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
  
          Fragment myFragment = myActivity.getFragmentManager().findFragmentByTag(myTag);
  
          if (myFragment != null) {
              ft.detach(myFragment);
          }
  
      }
  
      @Override
      public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
          // TODO Auto-generated method stub
  
      }
  
  }
  </code></pre>