title: Tab Layout and buttons in Android
body: <p>I have built an application in android using Tab Layout and it has 2 tabs. I want a different button on each of these tabs. But if I define button in main.xml, I get same button on both the tabs. </p>
  
  <p>I even tried defining the buttons separately in the class of each tab, but was getting some weird errors. can somebody please help me out with this. Below is my code:</p>
  
  <p><em><strong>FinalProj.java:</em></strong></p>
  
  <pre><code>package FinalProj.com;
  
  import android.app.Activity;
  import android.app.TabActivity;
  import android.content.Intent;
  import android.content.res.Resources;
  import android.os.Bundle;
  import android.widget.TabHost;
  
  public class FinalProj extends TabActivity {
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
  
          Resources res = getResources(); // Resource object to get Drawables
          TabHost tabHost = getTabHost();  // The activity TabHost
          TabHost.TabSpec spec;  // Resusable TabSpec for each tab
          Intent intent;  // Reusable Intent for each tab
  
          intent = new Intent().setClass(this, iFallApp.class);
  
          // Initialize a TabSpec for each tab and add it to the TabHost
          spec = tabHost.newTabSpec("artists").setIndicator("Artists",
                            res.getDrawable(R.drawable.icon))
                        .setContent(intent);
          tabHost.addTab(spec);
  
          // Do the same for the other tabs
          intent = new Intent().setClass(this, Settings.class);
          spec = tabHost.newTabSpec("albums").setIndicator("Albums",
                            res.getDrawable(R.drawable.icon))
                        .setContent(intent);
          tabHost.addTab(spec);
  
          tabHost.setCurrentTab(2);
      }
  }
  </code></pre>
  
  <p><em><strong>For Tab1 - iFallApp.java</em></strong></p>
  
  <pre><code>package FinalProj.com;
  
  import android.app.Activity;
  import android.os.Bundle;
  import android.widget.TextView;
  
  public class iFallApp extends Activity{
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          TextView textview = new TextView(this);
          textview.setText("This is the iFall tab");
          setContentView(textview);
      }
  }
  </code></pre>
  
  <p><em><strong>Tab 2 - Settings.java</em></strong></p>
  
  <pre><code>package FinalProj.com;
  
  import android.app.Activity;
  import android.os.Bundle;
  import android.widget.TextView;
  
  public class Settings extends Activity{
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          TextView textview = new TextView(this);
          textview.setText("This is the Settings tab");
          setContentView(textview);
      }
  }
  </code></pre>
  
  <p><em><strong>Main.xml:</em></strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;TabHost xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@android:id/tabhost"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"&gt;
  &lt;LinearLayout
          android:orientation="vertical"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:padding="5dp"&gt;
          &lt;TabWidget
              android:id="@android:id/tabs"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content" /&gt;
               &lt;FrameLayout
              android:id="@android:id/tabcontent"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:padding="5dp" /&gt;
  &lt;/LinearLayout&gt;
  &lt;/TabHost&gt;
  </code></pre>
  
  <p>I want to have one button along with TextView in iFallApp.java and one button and editText in Settings.java.</p>