我有一个片段类,从这个调用中有twopane layout 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"/>
我的班级是,
@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),但它的null,如果主类是一个活动它工作正常,但我需要主类是一个片段。任何人都可以帮助我。
答案 0 :(得分:1)
要在Fragments中嵌入Fragments,请调用getChildFragmentManager()而不是getActivity()。getSupportFragmentManager()