我正在使用自定义的 DialogFragment。在该onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)方法中,我对包含另一个导致应用程序崩溃的片段的布局进行膨胀。我该如何解决?
5864 次
1 回答
9
您不能嵌套Fragments在其他FragmentsXML 布局中。您必须使用代码添加它们。要将 aFragment插入另一个Fragment中,您必须使用特殊FragmentManager的 -a child FragmentManager。你可以从父母那里得到它Fragment:
//In the DialogFragment ('parent') get the child FragmentManager:
FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
transaction.transaction.add(new MyCustomChildFragment(), "CustomTag");
我通常Fragments在onActivityCreated().
于 2013-07-18T11:07:32.720 回答