选项卡例外:“您必须指定创建选项卡指示符的方法”
我的应用程序由三个选项卡组成,其中两个具有 ListView,一个只是具有 TextView 的活动。为了通过选项卡获取主要活动,我使用developers.anroid.com http 中的示例://developer.android.com/resources/tutorials/views/hello-tabwidget.html 根据这个例子,我的布局是:
<?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>
因此,下一个代码是活动代码(只有两页):
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);
}
}
每个意图都指向另一个活动,该活动在布局和代码中都有硬编码的 ListView 来从字符串数组定义它来自资源。但开始后我遇到异常 IllegalArgument Exception“”您必须指定一种创建选项卡指示器的方法”。这让我停下来,请帮助我。 谢谢大家
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>
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);
}
}
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这段代码运行完美,所以你应该尝试使
这
就像我所做的那样, 被分开了。也许不应该使用单个命令行来设置属性。
This code is works perfectly, so you should try to make
this
get separated as I had done. Maybe shoudn`t use single command line to set attrs.
我刚刚遇到了同样的问题。
我发现我的问题是 sp 的重用,
我这样做是为了解决问题:
使用不同的 TabSpec 值解决了我的问题。
I just had this same problem.
I found my problem was the reuse of sp
I did this to solve the problem:
using different TabSpec values fixed the issue for me.