TabHostとボタン付きのAndroid 1.5プログラミング
-
21-08-2019 - |
質問
私は現在のAndroid 1.5 SDKを試していると私はTabHost上の例のカップルを見てきました。 私は何をしようとしていることは、そのタスクを実行するために、それぞれのタブに異なるボタンを使用することです。
私が試した何 onClickListiner()とのonClick()を使用しました。私は、これはすべての開発者が使用するものだと思うが、私はLogCatのボタンが押されるたびに、ヌル例外を得続けます。
tab.add(...のsetContent(R.id.firstTabLayout)):また、私はので、私のようにタブを呼び出し、各XMLレイアウトを持っていますfirstTabLayout = layout for Button and TextView.
何が正しくTabHost下ボタン/ TextViewの作業を行うための最善の方法だろうか?
解決
私はあなたの問題がどこにあるか全くわからないんだけど、これは私が
の前に私のタブ付きの活動を設定した方法ですlayout.xml
<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:id="@+id/tab1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:id="@android:id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:id="@+id/tab2"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:id="@android:id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:id="@+id/tab3"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:id="@android:id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</FrameLayout>
Tab.java
public class InitialActivity extends TabActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout);
TabHost th = getTabHost();
th.addTab(th.newTabSpec("tab_1").setIndicator("Tab1").setContent(R.id.tab1));
th.addTab(th.newTabSpec("tab_2").setIndicator("Tab2").setContent(R.id.tab2));
th.addTab(th.newTabSpec("tab_3").setIndicator("Tab3").setContent(R.id.tab3));
}
}
次に、あなただけのタブ内の任意のビューにfindViewById()を使用することができ、またはそれらの間の共有名がある場合は、あなたがfindViewById(R.id.tab1).findViewById(R.id.text)
を行うことができます。
所属していません StackOverflow