gpt4 book ai didi

java - 如何在非 TabActivity 的 Activity 中创建 tabHost

转载 作者:行者123 更新时间:2023-12-01 15:37:09 27 4
gpt4 key购买 nike

我在 Activty 中创建了一个 tabHost,每次它到达 .addTab(Spec) 时都会崩溃。我在 Activity 中创建了选项卡主机,如下所示:

peopleTabHost = new TabHost(this);

然后我使用一种方法来添加选项卡(我可以这样做,因为我在 onCreat 之外将 peopleTabHost 定义为 Final)

    private void CreateNewTab(String tagName, String displayedName, Class<?> intentClass)
{
Intent intent = new Intent().setClass(this, intentClass);
TabHost.TabSpec spec = peopleTabHost.newTabSpec(tagName).setIndicator(displayedName);
spec.setContent(intent);
peopleTabHost.addTab(spec);
}

谢谢

最佳答案

我同意 sianis 的回答,但我还补充说,它可能会崩溃,因为您没有初始化(或至少没有显示)tabhost。

尝试在调用构造函数后立即运行 peopleTabHost.setup();

关于java - 如何在非 TabActivity 的 Activity 中创建 tabHost,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8701611/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com