FragmentTransaction必须在替换mainFrame后替换Fragment childview(FrameLayout)

时间:2017-11-09 07:11:17

标签: android android-fragments fragmenttransaction

我总共有三Map

1.BookAppointmentFirstFragment, 2.BookAppointment1和 3.ConfirmAppointment

我从Fragments(约会)到第一个片段(即FragmenttransactionMainFrag替换为" appointment_frame"。就像这个

BookAPpointmentFirst

从First FragmentManager fm=mContext.getSupportFragmentManager(); FragmentTransaction ft=fm.beginTransaction(); BookAppointmentFirstFragment bookAppointmentFirstFragment=new BookAppointmentFirstFragment(); ft.replace(R.id.appointment_frame, bookAppointmentFirstFragment); ft.addToBackStack(Constants.FRAG_TAG_APPOINTMENTS3); ft.commit(); (即Fragment)我通过" contentmain_home"替换了第二次交易(即Bookappointment1)。像这样。

BookAppointmentfirst

在上面之后我试图通过由appointment_frame替换从Bookappointment1到BookAppointment1 bookAppointment1 = new BookAppointment1(); FragmentManager fragMgnr = getFragmentManager(); FragmentTransaction fragtrans; fragtrans = fragMgnr.beginTransaction(); fragtrans.replace(R.id.content_mainhome, bookAppointment1); fragtrans.addToBackStack(Constants.FRAG_TAG_APPOINTMENTSBOOK1); fragtrans.commit(); 进行交易,但是我在这里遇到崩溃没有找到查看" appointment_main"。请帮助我如何做到这一点。

ConfirmFrgment

以上交易我遇到崩溃没有找到任何查看" appointment_frame"

1 个答案:

答案 0 :(得分:0)

由于 BookAppointment1 片段的布局中没有 appointment_frame 视图,您正在崩溃,我认为 appointment_frame < / strong>视图出现在 活动

所以你需要在片段

中这样调用
FragmentManager fragMgnr = getActivity().getSupportFragmentManager();
FragmentTransaction fragtrans;
fragtrans = fragMgnr.beginTransaction();
fragtrans.replace(R.id.appointment_frame, confirmAppointment);
fragtrans.addToBackStack(Constants.FRAG_TAG_APPOINTMENTSBOOK2);
fragtrans.commit();