I have 2 tabs: Report and Profile.
I want to add a different form (Textview, spinner, etc) in each of the tabs. For now im trying with a button and it should be different button in different tab.
But what i get is i have the same button in both tab. It should show button name ButtonReport in Report Tab and ButtonProfile in Profile Tab.
Below is the picture of it.

I am putting the button code in main.xml.
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</TabWidget>
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- Start Interface -->
<TableLayout android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/tableLayout1" android:alwaysDrawnWithCache="false">
<TableRow android:layout_height="fill_parent" android:id="@+id/tableRow3">
<TableLayout android:id="@+id/tableLayout2" android:layout_width="wrap_content" android:layout_height="wrap_content">
<Button android:text="Button Report" android:id="@+id/button1" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>
</TableLayout>
</TableRow>
</TableLayout>
<!-- End Interface -->
</FrameLayout>
</LinearLayout>
</TabHost>
This is my ReportActivity class and ProfileActivity(same code only different name)
package com.tab;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class ReportActivity extends Activity{
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
TextView text = new TextView(this);
text.setText("Artist");
setContentView(text);
}
}
This is my MainActivity class
package com.tab;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;
public class MainActivity extends TabActivity {
private TabHost aTab;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res = getResources();
aTab = getTabHost();
TabHost.TabSpec spec;
Intent intent;
//Report Tab
intent = new Intent(this, ReportActivity.class);
spec = aTab.newTabSpec("Report")
.setIndicator("Report", res.getDrawable(R.drawable.tab_icon))
.setContent(intent);
aTab.addTab(spec);
//Profile Tab
intent = new Intent(this, ProfileActivity.class);
spec = aTab.newTabSpec("Profile")
.setIndicator("Profile", res.getDrawable(R.drawable.tab_icon))
.setContent(intent);
aTab.addTab(spec);
aTab.setCurrentTab(1);
}
}
is there a way to have different form in different tab?
The best way (my opinion) is to use Fragments :
http://developer.android.com/guide/components/fragments.html
Fragment are for API Level 11 minimum, but you can work with a compatibility package :
http://android-developers.blogspot.ch/2011/03/fragments-for-all.html
So every tab will become a fragment.