我正在尝试创建一个带有两个选项卡的选项卡小部件来打开两个不同的活动,并编写以下布局来实现这一点,但它给了我一个NullPointerException。
我的错误在哪里?
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabhost"
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" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</FrameLayout>
</LinearLayout>
</TabHost>在扩展TabWidget的Java类中,我的onCreate方法中有以下代码:
setContentView(R.layout.more);
TabHost mTabHost = (TabHost) this.findViewById(R.id.tabhost);
mTabHost.setup();
Intent intent;
intent = new Intent().setClass(this, Settings.class);
mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator(
"Calculator",
getResources().getDrawable(R.drawable.tab01)).setContent(intent));
intent = new Intent().setClass(this, Post.class);
mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator(
"YouTube",
getResources().getDrawable(R.drawable.tab02)).setContent(intent));发布于 2010-02-18 15:33:24
如果要使用TabActivity扩展选项卡类,则必须
要使用选项卡相关控件的id,如"@android:id/tabhost“
我使用的是"@+id/tabhost“,这是错误的,但在通过Activity类扩展它的情况下也没问题。
而我在布局上遇到的上述问题将不会出现…
标签教程也有一点bit,可以用下面的例子来解决。Example
https://stackoverflow.com/questions/2282067
复制相似问题