レポートとプロファイルの 2 つのタブがあります。
各タブに別のフォーム (Textview、スピナーなど) を追加したいと考えています。今のところボタンを試していますが、別のタブでは別のボタンにする必要があります。
しかし、私が得るのは、両方のタブに同じボタンがあるということです。ボタン名 ButtonReport を [レポート] タブに表示し、ButtonProfile を [プロファイル] タブに表示する必要があります。
以下はその写真です。
ボタンのコードを 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>
これは私のReportActivityクラスとProfileActivityです(同じコードで名前が異なるだけです)
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);
}
}
これは私の MainActivity クラスです
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);
}
}
別のタブで別のフォームを持つ方法はありますか?