title: Best way to implement tabs in android?
body: <p>I have read looked through some code that implements tabs on the bottom of the app's page. And there is no deprecated method/class inside the code, and to me it is a very easy and clean way to implements tabs.</p>
  
  <p>But I heard the new way of implementing tabs is to use fragments.</p>
  
  <p>So, which one is better? And why?</p>
  
  <p>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:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="vertical" &gt;
  
      &lt;TabHost
          android:id="@+id/edit_item_tab_host"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent" &gt;
  
          &lt;TabWidget
              android:id="@android:id/tabs"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_gravity="bottom" /&gt;
  
  
              &lt;FrameLayout
                  android:id="@android:id/tabcontent"
                  android:layout_width="fill_parent"
                  android:layout_height="fill_parent"
                  android:paddingTop="65px" &gt;
  
              &lt;LinearLayout
                  android:id="@+id/edit_item_date_tab"
                  android:layout_width="fill_parent"
                  android:layout_height="fill_parent"
                  android:orientation="vertical"
                  android:padding="5px" &gt;
  
                  &lt;TextView
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:text="date"
                      android:textStyle="bold" /&gt;
  
              &lt;/LinearLayout&gt;
  
              &lt;LinearLayout
                  android:id="@+id/edit_item_geocontext_tab"
                  android:layout_width="fill_parent"
                  android:layout_height="fill_parent"
                  android:orientation="vertical"
                  android:padding="5px" &gt;
  
                  &lt;TextView
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:text="lieu"
                      android:textStyle="bold" /&gt;
              &lt;/LinearLayout&gt;
  
              &lt;LinearLayout
                  android:id="@+id/edit_item_text_tab"
                  android:layout_width="fill_parent"
                  android:layout_height="fill_parent"
                  android:orientation="vertical"
                  android:padding="5px" &gt;
              &lt;/LinearLayout&gt;
          &lt;/FrameLayout&gt;
      &lt;/TabHost&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><code>MainActivity</code> class:</p>
  
  <pre><code>import android.app.Activity;
  import android.os.Bundle;
  import android.widget.TabHost;
  import android.widget.TabHost.TabSpec;
  
  public class MainActivity extends Activity {
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
  
  
  
          TabHost tab_host = (TabHost) findViewById(R.id.edit_item_tab_host);
          // don't forget this setup before adding tabs from a tabhost using a xml view or you'll get an nullpointer exception
          tab_host.setup(); 
  
          TabSpec ts1 = tab_host.newTabSpec("TAB_DATE");
          ts1.setIndicator("tab1");
          ts1.setContent(R.id.edit_item_date_tab);
          tab_host.addTab(ts1);
  
          TabSpec ts2 = tab_host.newTabSpec("TAB_GEO");
          ts2.setIndicator("tab2");
          ts2.setContent(R.id.edit_item_geocontext_tab);
          tab_host.addTab(ts2);
  
          TabSpec ts3 = tab_host.newTabSpec("TAB_TEXT");
          ts3.setIndicator("tab3");
          ts3.setContent(R.id.edit_item_text_tab);
          tab_host.addTab(ts3);
  
          tab_host.setCurrentTab(0);
  
  
  
  
          }
  }
  </code></pre>