0
私のコードに奇妙なエラーがあります。 私はユーザーのロゴに表示しようとしていますが、その後にタブを表示しようとしています。 はきれいにし、まだ同じエラーがプロジェクトをビルドしようとしました、と私は輸入R. を使用していけない。しかし、私の問題は、いくつかの奇妙なエラーです:タブとAsyncTaskのsetContentViewでエラーが発生しました
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>
助けてくれてありがとう!あなたがTabhost
を使用する場合
setcontentview(R.layout.logoscreen)を持っている必要があります。 –
ありがとう!これを変更して、コードビューを(TabHost)tabs.this.findViewById(android.R.id.tabhost)に変更します。よく働く! –