Android 片段上的双窗格布局创建空对象

Android twopane layout on fragment creates null object

我有一个片段 class,来自这个调用的双窗格布局 invoices_view.xml

<fragment class="lk.ezbiz.mobile.ui.InvoiceListFragment"
    android:id="@+id/contact_list"
    android:layout_height="match_parent"
    android:layout_width="0dp"
    android:layout_weight="@integer/contact_list_percent"/>

<fragment class="lk.ezbiz.mobile.ui.InvoiceDetailFragment"
    android:id="@+id/contact_detail"
    android:layout_height="match_parent"
    android:layout_width="0dp"
    android:layout_weight="@integer/contact_detail_percent"/>

而我的 class 是,

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = null;

    try {
        rootView = inflater.inflate(R.layout.invoices_view, container, false);
        Log.d(TAG, "onCreateView");

        isTwoPaneLayout = getResources().getBoolean(R.bool.has_two_panes);

        if (isTwoPaneLayout) {

            mInvoiceDetailFragment = (InvoiceDetailFragment)
                    getActivity().getSupportFragmentManager().findFragmentById(R.id.contact_detail);
        }

    } catch (Exception ex) {
        Log.e(TAG, "onCreateView: " + ex.toString());
    }

    return rootView;
}

要在左窗格中显示所选项目,我需要使用此 InvoiceDetailFragment 对象 (mInvoiceDetailFragment),但它为空,如果主要 class 是一个 activity 它工作正常,但我需要主要 class 是一个片段。谁能帮帮我

要在 Fragment 中嵌套 Fragment,请调用 getChildFragmentManager() 而不是 getActivity().getSupportFragmentManager()