ошибка с setContentView на вкладках и AsyncTask - PullRequest
0 голосов
/ 26 февраля 2012

У меня странная ошибка с моим кодом.Я пытаюсь показать пользователю логотип и после этого отобразить вкладки.Попытался очистить и построить проект все те же ошибки, и я не использую импорт 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>

спасибо за помощь !!!

1 Ответ

2 голосов
/ 26 февраля 2012

если вы используете Tabhost, тогда должно быть android:id="@android:id/tabhost", а у вас

android:id="@+id/tabhost"
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...