title: using a FragmentTabHost with a ViewPager
body: <p>I want to create a swipe tab interface using a <code>FragmentTabHost</code> with a <code>ViewPager</code>. So far I got the Fragments to slide. The only thing that's happening is that the fragments are able slide behind the tabs which are <strong>disabled/stuck</strong> and not working. How can I make the FragmentTabHost tabs work with the ViewPager for swiping between tabs?</p>
  
  <p>I tried using FragmentTabHost without the viewpager, it works fine, but its just not working with the viewpager.</p>
  
  <p>here's a screenshot of what it looks like:
  <img src="https://i.stack.imgur.com/KZHac.png" alt="enter image description here"></p>
  
  <p>Main Java source code:</p>
  
  <pre><code>import java.util.List;
  import java.util.Vector;
  
  import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.support.v4.app.FragmentActivity;
  import android.support.v4.app.FragmentManager;
  import android.support.v4.app.FragmentPagerAdapter;
  import android.support.v4.app.FragmentTabHost;
  import android.support.v4.view.ViewPager;
  
  
  
  public class MainActivity extends FragmentActivity {
   private FragmentTabHost mTabHost;
   private ViewPager pager;
   private MyPagerAdapter adapter;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
       mTabHost = (FragmentTabHost)findViewById(android.R.id.tabhost);
  
          pager = (ViewPager) findViewById(R.id.viewpager);                                   
          List&lt;Fragment&gt; fragments = new Vector&lt;Fragment&gt;();
          fragments.add(Fragment.instantiate(this, BatteryFragment.class.getName()));
          fragments.add(Fragment.instantiate(this, DeviceFragment.class.getName()));
          fragments.add(Fragment.instantiate(this, NetworkFragment.class.getName()));         
          adapter = new MyPagerAdapter(getSupportFragmentManager(),       fragments);
  
          pager.setAdapter(adapter);
  
          mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
  
          mTabHost.addTab(mTabHost.newTabSpec("battery").setIndicator("Battery",
                  getResources().getDrawable(R.drawable.ic_battery_tab)),
                  BatteryFragment.class, null);
          mTabHost.addTab(mTabHost.newTabSpec("network").setIndicator("Network",
                  getResources().getDrawable(R.drawable.ic_network_tab)),
                     NetworkFragment.class, null);
          mTabHost.addTab(mTabHost.newTabSpec("device").setIndicator("Device",
                  getResources().getDrawable(R.drawable.ic_device_tab)),
                  DeviceFragment.class, null);
  
  
  
  
  }
  
  
  public class MyPagerAdapter extends FragmentPagerAdapter {
      private List&lt;Fragment&gt; fragments;
  
      public MyPagerAdapter(FragmentManager fm, List&lt;Fragment&gt; fragments) {
          super(fm);
          this.fragments = fragments;
      }       
  
      @Override
      public Fragment getItem(int arg0) {
          // TODO Auto-generated method stub
          return this.fragments.get(arg0);
      }
  
      @Override
      public int getCount() {
          // TODO Auto-generated method stub
          return this.fragments.size();
      }
  
  }
  
  
  }
  </code></pre>
  
  <p>XML code:
      </p>
  
  <pre><code>&lt;LinearLayout
      android:orientation="vertical"
      android:layout_width="match_parent"
      android:layout_height="match_parent"&gt;
  
      &lt;TabWidget
          android:id="@android:id/tabs"            
          android:orientation="horizontal"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_weight="0"/&gt;       
  
      &lt;FrameLayout
          android:id="@android:id/tabcontent"
          android:layout_width="0dp"
          android:layout_height="0dp"
          android:layout_weight="0"/&gt;
  
      &lt;FrameLayout
          android:id="@+id/realtabcontent"
          android:layout_width="match_parent"
          android:layout_height="0dp" /&gt;
  
       &lt;android.support.v4.view.ViewPager
          android:id="@+id/viewpager"
          android:layout_width="fill_parent"
          android:layout_height="0dp"
          android:layout_weight="1"/&gt;         
  
  &lt;/LinearLayout&gt;
  
  &lt;/android.support.v4.app.FragmentTabHost&gt;
  </code></pre>