フラグメント内に TabHost を作成しています。fragmentActivity に 2 つのフラグメントがあり、右側のフラグメントにタブホストが必要です。ただし、TabHost は表示されず、アクティビティは強制的に閉じられ、nullpointerexception が発生します
これは、TabHost を呼び出しているフラグメントのコードです
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.menucat, container, false);
mTabHost=(TabHost)getView().findViewById(android.R.id.tabhost);
TabHost.TabSpec spec;
mTabHost.setup();
intent=new Intent(getActivity(),Activity1.class);
spec = mTabHost.newTabSpec("soups").setIndicator("Soups").setContent(intent);
mTabHost.addTab(spec);
mTabHost.setCurrentTab(0);
return view;
}
これは、タブホストを作成するために使用している私のレイアウトです。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<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">
<TabWidget
android:id="@android:id/tabs"
android:visibility="gone"
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"/>
</LinearLayout>
</TabHost>