gpt4 book ai didi

java - Android tabhost 问题...包含代码

转载 作者:行者123 更新时间:2023-11-29 22:32:24 25 4
gpt4 key购买 nike

当我尝试启动包含 tabhost 的 Activity 时出现以下错误。

08-25 16:51:42.551: ERROR/AndroidRuntime(27863): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.paratransit/com.paratransit.jobDialog}: java.lang.RuntimeException: Could not create tab content because could not find view with id 2131165185

这是我的代码。谁能帮忙?

Java

public Class jobDialog extends TabActivity {

TabHost tabs;
int jobCurrentTab = -1;

@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

Bundle extras = getIntent().getExtras();
setContentView(R.layout.job_dialog);

tabs = getTabHost();
tabs.setup();
setupTabs();
}

public void setupTabs()
{
TabSpec tspec1 = tabs.newTabSpec("First Tab");
tspec1.setIndicator("Summary", getResources().getDrawable(R.drawable.tab_main)).setContent(R.id.jobDetail1);
tabs.addTab(tspec1);
TabSpec tspec2 = tabs.newTabSpec("Second Tab");
tspec2.setIndicator("Details", getResources().getDrawable(R.drawable.tab_message)).setContent(R.id.jobDetail2);
tabs.addTab(tspec2);
TabSpec tspec3 = tabs.newTabSpec("Third Tab");
tspec3.setIndicator("Notes", getResources().getDrawable(R.drawable.tab_jobs)).setContent(R.id.jobDetail3);
tabs.addTab(tspec3);

XML

<?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"
android:padding="5dp">

<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"
android:padding="5dp" />

<LinearLayout
android:id="@+id/jobDetail1"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

</LinearLayout>

<LinearLayout
android:id="@+id/jobDetail2"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

</LinearLayout>

<LinearLayout
android:id="@+id/jobDetail3"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

</LinearLayout>

</LinearLayout>
</TabHost>

最佳答案

我认为 3 个线性布局,jobDetail1->3 应该在 FrameLayout xml 元素中。 FrameLayout 的要点是所有 View 都在彼此之上,因此选项卡管理器可以决定显示哪个 View 。

关于java - Android tabhost 问题...包含代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3570255/

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