gpt4 book ai didi

android - 您的内容必须有一个 TabHost,其 id 属性为 'android.R.id.tabhost'

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:48:24 25 4
gpt4 key购买 nike

我有一个问题:

Java 代码

public class VisualizzaListaActivity extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Reusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab

// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, DaAcquistareActivity.class);

// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("daAcquistare").setIndicator("Da Acquistare").setContent(intent);
tabHost.addTab(spec);

// Do the same for the other tabs
intent = new Intent().setClass(this, AcquistatiActivity.class);
spec = tabHost.newTabSpec("acquistati").setIndicator("Acquistati").setContent(intent);
tabHost.addTab(spec);

tabHost.setCurrentTab(0);
}

}

XML 代码

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost" <-------------- It's 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>
</TabHost>

和 LogCat

12-16 15:26:22.519: E/AndroidRuntime(8262): java.lang.RuntimeException: Unable to start activity ComponentInfo{android.smile.matteo.spesaPRO/android.smile.matteo.spesaPRO.VisualizzaListaActivity}: java.lang.RuntimeException: Your content must have a TabHost whose id attribute is 'android.R.id.tabhost'             
12-16 15:26:22.519: E/AndroidRuntime(8262): Caused by: java.lang.RuntimeException: Your content must have a TabHost whose id attribute is 'android.R.id.tabhost'
12-16 15:26:22.519: E/AndroidRuntime(8262): at android.smile.matteo.spesaPRO.VisualizzaListaActivity.onCreate(VisualizzaListaActivity.java:13)

问题

谁能告诉我为什么会这样

Your content must have a TabHost whose id attribute is 'android.R.id.tabhost'

当android:id = @android:id/tabhost?

最佳答案

我相信消息的意思是:

     <TabHost android:id="@+id/tabhost"

应该改为:

     <TabHost android:id="@android:id/tabhost"

关于android - 您的内容必须有一个 TabHost,其 id 属性为 'android.R.id.tabhost',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8538437/

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