Android 制表符的例外情况:";必须指定创建选项卡指示器的方法";

Android 制表符的例外情况:";必须指定创建选项卡指示器的方法";,android,exception,tabs,Android,Exception,Tabs,我的应用程序由三个选项卡组成,其中两个具有ListView,一个只是带有TextView的活动。我使用developers.anroid.com中的示例来获取选项卡的主要活动 根据这个例子,我的布局是: <?xml version="1.0" encoding="utf-8"?> <TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_paren

我的应用程序由三个选项卡组成,其中两个具有ListView,一个只是带有TextView的活动。我使用developers.anroid.com中的示例来获取选项卡的主要活动 根据这个例子,我的布局是:

<?xml version="1.0" encoding="utf-8"?>
<TabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@android:id/tabhost"
>

<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"
/>


</LinearLayout>

</TabHost>
}

每个意图都指向另一个活动,该活动在布局中具有硬编码的ListView,并通过资源中的字符串数组来定义它。但在开始之后,我得到了一个例外 IllegalArgument异常“您必须指定一种创建选项卡指示器的方法”。这会使我停止,请帮助我。 谢谢大家

    Intent i;
    i = new Intent().setClass(this, Tab1.class);
    TabSpec sp = th.newTabSpec("Tab1");
    sp.setIndicator("alma");
    sp.setContent(i);
    th.addTab(sp);

    i = new Intent().setClass(this, Tab2.class);
    sp = th.newTabSpec("Tab2");
    sp.setIndicator("alma2");
    th.addTab(sp);
    th.setCurrentTab(0);
这段代码工作得非常完美,所以您应该尝试 这个


像我做的那样分开。也许不应该使用单个命令行来设置属性。

我只是遇到了同样的问题

我发现我的问题是sp的重用

我这样做是为了解决问题:

TabSpec spec1=tabHost.newTabSpec("Tab 1");
    spec1.setContent(R.id.tab1);
    spec1.setIndicator("Tab 1",getResources().getDrawable(R.drawable.icon_tab1_config));

TabSpec spec2=tabHost.newTabSpec("Tab 2");
    spec2.setIndicator("Tab 2",getResources().getDrawable(R.drawable.icon_tab2_config));
    spec2.setContent(R.id.tab2);
使用不同的TabSpec值修复了这个问题

spec = tabHost.newTabSpec("Page 2").setIndicator("Page 2", res.getDrawable(R.drawable.icon))
TabSpec spec1=tabHost.newTabSpec("Tab 1");
    spec1.setContent(R.id.tab1);
    spec1.setIndicator("Tab 1",getResources().getDrawable(R.drawable.icon_tab1_config));

TabSpec spec2=tabHost.newTabSpec("Tab 2");
    spec2.setIndicator("Tab 2",getResources().getDrawable(R.drawable.icon_tab2_config));
    spec2.setContent(R.id.tab2);