пытается создать экран приветствия с AsyncTask

1

Я пытаюсь создать экран приветствия creat и через некоторое время, чтобы отобразить мои вкладки. Но получите некоторую ошибку, например:

 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.News/startPakage.tabs}: java.lang.RuntimeException: Your content must have a TabHost whose id attribute is 'android.R.id.tabhost'

мои вкладки в одном файле xml, который работает хорошо, прежде чем я сделал asynctask. мой код:

    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 Integer doInBackground(Void... params) {

          int waited = 0;
          while (waited < 5000) {
          try {
            this.wait(100);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
             waited += 100;
          }
            return 1;
    }

    protected void onPostExecute(Integer result) {

        setContentView(R.layout.tabs);

        Resources res = getResources(); // Resource object to get Drawables
        TabHost tabHost = getTabHost();  // The activity 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 для приветствия:

<?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" />

</LinearLayout>

и вкладки xml

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

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

  • 0
    Где находится закрывающий тег для TabHost?
Теги:
android-asynctask

2 ответа

1
Лучший ответ

У вашей асинтезности нет метода gettabhost(), вы должны переписать эту часть. Gettabhost доступен только для класса, который расширяет tabactivity, а не вашу асинтезу.

ура

1

Ваш tabhost должен иметь идентификатор android.R.id.tabhost этом примере... http://dewful.com/?p=15

  • 0
    хорошо сделал это tabs = (TabHost) this.findViewById (android.R.id.tabhost); но я получаю сообщение об ошибке, этот метод ошибки findViewById (int) не определен для типа tabs.GetDataTask, чтобы удалить R, но все же получить это
  • 0
    ооо ... яр см. в ссылке и его изменение в xml файле ....

Ещё вопросы

Сообщество Overcoder
Наверх
Меню