我的代码出现了一个奇怪的错误。 我试图向用户徽标显示,然后显示选项卡。 试图清理和构建项目仍然是相同的错误,我不使用导入R. 但我的问题是一些奇怪的错误:
java.lang.RuntimeException: Your content must have a TabHost whose id attribute is 'android.R.id.tabhost'
我的应用有错误
setContentView(R.layout.logoscreen);
我的代码是:
public class tabs extends TabActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.logoscreen);
new GetDataTask(this).execute();
}
private class GetDataTask extends AsyncTask<Void, Void, Integer> {
Context context;
GetDataTask(Context context){this.context=context;}
protected void onPostExecute(Integer result) {
//tabs.this.setContentView(R.layout.tabs);
setContentView(R.layout.logoscreen);
//setContentView(R.layout.tabs);
TabHost tabHost= (TabHost)tabs.this.findViewById(R.id.tabhost);
TabHost.TabSpec spec; // Resusable 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(context,start.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("Heb news").setIndicator("Heb news").setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(context, rusNewsP.ListRusNews.class);
spec = tabHost.newTabSpec("Rus News").setIndicator("Rus News").setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
}
}
我的xml文件是logoscreen.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon" />
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+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="@+id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@+id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" />
</LinearLayout>
</TabHost>
</LinearLayout>
感谢您的帮助!!!
答案 0 :(得分:2)
如果您使用Tabhost
,那么必须有android:id="@android:id/tabhost"
并且您有
android:id="@+id/tabhost"