在 DialogFragment 中放置选项卡

Placing Tabs in DialogFragment

我正在尝试将 TabHost 放在 DialogFragment 中,但目前它是 none 功能并且 returns 为空:

tabs.findViewById(R.id.tabHost);

如何在DialogFragment中初始化tabhost来让tab出现?

选项卡式对话日志 class:

public class InviteFriendTabbedAlertDialog extends DialogFragment {

    TabHost tabs;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        //return inflater.inflate(R.layout.invite_friend_tabbed_dialog, null);

        // Add tabs
        tabs.findViewById(R.id.tabHost);

        tabs.setup();

        TabHost.TabSpec tabpage1 = tabs.newTabSpec("one");
        tabpage1.setContent(R.id.shareIndividual);
        tabpage1.setIndicator("Tab 1", getResources().getDrawable(R.drawable.abc_ab_solid_dark_holo));

        TabHost.TabSpec tabpage2 = tabs.newTabSpec("two");
        tabpage2.setContent(R.id.shareGroup);
        tabpage2.setIndicator("Tab 2", getResources().getDrawable(R.drawable.abc_ab_bottom_transparent_light_holo));

        tabs.addTab(tabpage1);
        tabs.addTab(tabpage2);

        return inflater.inflate(R.layout.invite_friend_tabbed_dialog, null);

    }


}

选项卡式布局文件:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TabHost
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/tabHost"
        android:layout_gravity="center_horizontal">

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical">

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

            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">

                <LinearLayout
                    android:id="@+id/shareIndividual"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:orientation="vertical"></LinearLayout>

                <LinearLayout
                    android:id="@+id/shareGroup"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:orientation="vertical"></LinearLayout>

            </FrameLayout>
        </LinearLayout>
    </TabHost>
</RelativeLayout>

初始化 tabs 并使用扩展视图,其中有带 tabHost 的 TabHost 来初始化 tabs 变量:

@Override
    public View onCreateView(LayoutInflater inflater, 
                          ViewGroup container, Bundle savedInstanceState) {
      View  view=inflater.inflate(R.layout.invite_friend_tabbed_dialog, null);

        // Add tabs
        tabs=(TabHost)view.findViewById(R.id.tabHost);
        //...your code here
        return view;
    }