0

FragmentTabHostIm ' を追加しようとしてFragmentいます (これは別のタブ ウィジェットのコンテンツです。

次のxmlを使用しました。

<android.support.v4.app.FragmentTabHost
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@android:id/tabhost"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
        <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_weight="0"/>
        <FrameLayout
                android:id="@+id/realtabcontent"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"/>
        <TabWidget
                android:id="@android:id/tabs"
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0"/>

    </LinearLayout>
</android.support.v4.app.FragmentTabHost>

そして私FragmentonCreateView()方法では:

View basicSearchView = inflater.inflate(R.layout.search_layout, container, false);
        try {
        mTabHost = (FragmentTabHost) basicSearchView.findViewById(android.R.id.tabhost);
        LocalActivityManager mLocalActivityManager = new LocalActivityManager(this, false);
        mTabHost.setup(mLocalActivityManager);

        TabHost.TabSpec tab = mTabHost.newTabSpec("my tab content");

        tab.setContent(new Intent(getActivity(), JoinActivity.class));
        tab.setIndicator("Test", getResources().getDrawable(R.drawable.search_pheeds_selector));
        mTabHost.addTab(tab);
        }
        catch (Exception e) {
            Log.e("Udi",e.getMessage());
        }

        return basicSearchView;

最初に次のエラーが発生しました。

ERROR/Udi(25726): Must call setup() that takes a Context and FragmentManager

その後、セットアップを次のように変更しました。

mTabHost.setup(getActivity(), getChildFragmentManager(), R.id.realtabcontent);

そして、代わりにこのエラーが発生しました:

ERROR/Udi(25996): Did you forget to call 'public void setup(LocalActivityManager activityGroup)'?

タブホストを の中に入れる適切な方法はありますFragmentか?

4

1 に答える 1

1

タブコンテンツに Fragment オブジェクトを使用できる特別な TabHost であるFragmentTabHostと明確に述べているクラスのドキュメントを読んでいません。. したがって、タブをアクティビティに設定することはできず、アクティビティをフラグメントにしようとしているため、とにかく意味がありません(逆にする必要があります)。FragmentTabHost

したがって、コードを変更してフラグメントをタブのコンテンツとして使用するか、通常TabHostActivityアクティビティをタブとして使用し続けるようにします (このオプションは非推奨であり、実際には最初のオプションを使用する必要があります)。

タブホストをフラグメント内に配置する適切な方法はありますか?

リンクしたドキュメントには例があります。間違っていなければ、サポート ライブラリのサンプルにいくつかの例があります。

于 2013-03-11T13:41:44.727 に答える