2012-01-02 9 views
0

私はTabHostを作成し、4つのアクティビティのインテントをタブで割り当てました。これらはうまくいくようです。私の唯一の問題は、アクティビティのコンテンツがtabhostビューのframelayout #tabcontent内に表示されていないことです。Android TabHostのコンテンツが表示されない

私は正式な参照に従って、解決策をインターネットでスキャンしましたが、問題の内容を確認することはできません。

Log.v( "Activity"、 "Reports")はantに記録されているため、アクティビティが実行されます。したがって、問題を引き起こしているReportsActivityのsetContentView()を推測しています。しかし、私はこれに新しいので、私は本当に伝えることはできません。 (何も生成されたエラーはありません)

は、これは私のtabhost

<?xml version="1.0" encoding="utf-8"?> 
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@android:id/tabhost" 
    android:background="#FFFFFF"> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:background="#FFFFFF"> 

     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="0" /> 

     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:padding="5sp" 
      android:layout_weight="1" /> 

    </LinearLayout> 

</TabHost> 

である。これは私が私のTabActivityにタブを追加する方法

// Glob 
Intent intent; 
TabHost tabHost = getTabHost(); 
TabHost.TabSpec spec; 
Resources res = getResources(); 

// Reports tab 
intent = new Intent().setClass(this, ReportsActivity.class); 
spec = tabHost.newTabSpec("reports") 
     .setIndicator(
       res.getText(R.string.reports), 
       res.getDrawable(R.drawable.reports)) 
     .setContent(intent); 
tabHost.addTab(spec); 

であり、これは私のコンテンツ活動である(R.layout.reportsは、 =のTextViewとのLinearLayout)

public class ReportsActivity extends Activity { 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.reports); 

     Log.v("Activity", "Reports"); 
    } 
} 

答えて

0

は、このようなあなたのTabSpecを実装してみてください。

intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 

spec = tabHost.newTabSpec("reports") 
       .setIndicator(
        res.getText(R.string.reports), 
        res.getDrawable(R.drawable.reports)) 
       .setContent(intent); 
+0

TabSpecにはaddFlagsメソッドがありませんので、代わりにフラグを使用しようとしましたが、タブコンテンツにはReportsActivity線形レイアウト。 **編集:**私のReportsActivityは、デフォルトのアクティビティスーパークラス以外のアクティビティを拡張する必要がありますか? – Daniel

+0

xmlでTabWidgetを削除すると、FrameLayoutは突然アクティビティの内容を表示します。 TabWidgetがFrameLayoutと重なっているかどうかを確認するために余白を使用しようとしますが、そうではありません(私は思っています)。 TabWidgetはこれと何か関係がありますか? – Daniel

+0

私は、あなたがタブスペックの外にインテントを初期化したのを見ていませんでした。 addFlagはインテントに属します。私の修正された答えを見てください。 – Dyonisos

0

これは、既定で水平レイアウトに設定されているLinearLayoutを選択したためです。 問題を修正するはずのLinearLayoutタグの中にandroid:orientation = "vertical"を設定した場合

関連する問題