0
我的代碼有一個奇怪的錯誤。 我試圖展示給用戶標識,然後顯示標籤。 努力整頓和建設項目仍然是相同的錯誤,我不使用進口R. 但我的問題是一些奇怪的錯誤:與選項卡上的setContentView和AsyncTask錯誤
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>
感謝您的幫助!
的setContentView(R.layout.logoscreen); – 2012-02-26 19:32:53
非常感謝!改變這一點,並改變我的代碼視圖(TabHost)tabs.this.findViewById(android.R.id.tabhost);很棒! – 2012-02-26 19:33:25