异常与标签:"必须指定一个方法来创建选项卡指示器" [英] Exception with Tabs: "you must specify a way to create tab indicator"
问题描述
我的应用程序由三个选项卡,其中两个有ListView和一种是与TextView的只是活动。要使用标签获取主要活动我使用developers.anroid.com HTTP的例子://developer.android.com/resources/tutorials/views/hello-tabwidget.html
根据这个例子我的布局是:
My application consists three tabs and two of them have the ListView and one is just activity with TextView. To get main activity with Tabs I use the example from developers.anroid.com http://developer.android.com/resources/tutorials/views/hello-tabwidget.html According to this example my layout is:
<?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>
所以,下次code是活动的code(只有两页):
So, next code is code of activity (there are only two pages):
public class MainActivity extends TabActivity {
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.tabs_layout_start_page);
Resources res = getResources();
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
intent = new Intent(this, ListViewTab1Activity.class);
spec = tabHost.newTabSpec("Page1").setIndicator("Page 1", res.getDrawable(R.drawable.icon))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent(this, ListViewTab2Activity.class);
spec = tabHost.newTabSpec("Page 2").setIndicator("Page 2", res.getDrawable(R.drawable.icon))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(1);
}
}
每一个意图指向另一个活动,该公司在布局和code硬codeD的ListView来从资源字符串数组定义它。但启动后,我得到异常
IllegalArgument异常,你必须指定一个方法来创建选项卡指示器。这让我停了下来,请帮助我。
感谢大家。
Every intent is pointed to another activity, which has hard-coded ListView in layout and code to define it from string-array from resources. But after starting I get exception IllegalArgument Exception ""you must specify a way to create tab indicator". and it makes me stopped, please, help me. thanks for everyone
推荐答案
我只是有这个同样的问题。
I just had this same problem.
我发现我的问题是SP的重用
I found my problem was the reuse of sp
我这样做是为了解决问题:
I did this to solve the problem:
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值确定的问题对我来说。
using different TabSpec values fixed the issue for me.
这篇关于异常与标签:&QUOT;必须指定一个方法来创建选项卡指示器&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!