2012-02-25 11 views
1

私は、ウェルカム画面を作成しようとしていて、しばらくしてからタブを表示しようとしています。 しかし、のようないくつかのエラーを取得:ウェルカム画面をAsyncTaskで作成しようとしています

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' 

私はasynctaskをした前によく働く1つのXMLファイル、上の私のタブ。 私のコードは次のとおりです。

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の終了タグはありますか? –

答えて

1

あなたasynctaskは、あなたがこの部分を書き換える必要があります番目の電子のgettabhost()メソッドを持っていません。 Gettabhostは、asynctaskではなく、tabactivityを拡張するクラスでのみ使用できます。

乾杯

1

あなたtabhostがandroid.R.id.tabhost IDは、この例を見ている必要があります... http://dewful.com/?p=15

+0

OKこのタブは=(TabHost)this.findViewById(android.R.id.tabhost);しかし、私はこのエラーメソッドをエラーが発生していますfindViewById(int)型の定義されていませんが削除されますが、これを取得するts.GetDataTask –

+0

ohh ... yarリンクで参照してくださいとXMLファイルの変更.... –

関連する問題