首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >多个TabWidget?

多个TabWidget?
EN

Stack Overflow用户
提问于 2011-08-29 19:56:49
回答 2查看 1K关注 0票数 0

如何在一个tabhost中创建多个tabwidget,当我这样做时,我会得到空指针异常

代码语言:javascript
复制
 <?xml version="1.0" encoding="utf-8"?>

<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android: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="0dip"
            android:layout_weight="1" />

        <TabWidget android:id="@android:id/tabs"
            android:layout_width="fill_parent" android:layout_height="wrap_content" />
    </LinearLayout>
</TabHost> 
EN

回答 2

Stack Overflow用户

发布于 2011-08-29 20:03:41

你不需要第二个TabWidget在那里。

如果您询问有关向TabHost添加多个选项卡的问题,请参阅本教程:http://developer.android.com/resources/tutorials/views/hello-tabwidget.html

仔细检查步骤6中创建newTabSpec()的位置。

票数 1
EN

Stack Overflow用户

发布于 2015-11-06 19:05:46

要添加多个选项卡,您必须创建tabSpec对象,然后使用TabbHost的.addTab()方法添加每个选项卡规范。

示例

代码语言:javascript
复制
myTabHost = (FragmentTabHost)findViewById(android.R.id.tabhost);
myTabHost.setup(this,getsupportFragmentManager(),android.R.id.tabcontent);
myTabHost.addTab(myTabHost.newTabSpec("tab1").setIndicator("Tab1",null), SomeFragmentClass.class,null);

myTabHost.addTab(myTabHost.newTabSpec("tab2").setIndicator("Tab2",null), AnotherFragmentClass.class,null); // just pass fragment classes with it

我希望这会有帮助..。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7229738

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档