FragmentTabHost不显示片段

时间:2014-08-01 13:09:15

标签: java android tabs

我正在尝试在片段中实现FragmentTabHost(使用support.v13),但是我正在向其中添加片段,但是当我单击选项卡时,内容将保持为空。

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

        mTabHost = (FragmentTabHost) view.findViewById(android.R.id.tabhost);
        mTabHost.setup(getActivity(), getChildFragmentManager(), R.id.realtabcontent);

        Bundle args = new Bundle();
        args.putInt("itemId", itemId);

        mTabHost.addTab(mTabHost.newTabSpec("frag1").setIndicator("Home"), HomeFragment.class, null);
        mTabHost.addTab(mTabHost.newTabSpec("frag2").setIndicator("A"), HomeFragment.class, null);
        mTabHost.addTab(mTabHost.newTabSpec("frag3").setIndicator("L"), HomeFragment.class, null);

        // Inflate the layout for this fragment
        return view;
    }

这是它的XML:

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

    <android.support.v13.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="@+id/realtabcontent"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"/>

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

</LinearLayout>

0 个答案:

没有答案