我有一个活动。在这个Activity中,我设置了Fragment B.然后在Fragment B中,我调用了DialogFragment C.现在我想在DialogFragment KonfirmasiPembayaranPesertaFragment 中调用方法,但该方法没有被调用
这就是我在片段B中调用DialogFragment KonfirmasiPembayaranPesertaFragment 的方式
FragmentManager fragmentManager = getChildFragmentManager();
KonfirmasiPembayaranPesertaFragment manageFaq = new KonfirmasiPembayaranPesertaFragment();
manageFaq.setTargetFragment(this, 0);
manageFaq.setCancelable(false);
manageFaq.setDialogTitle("Konfirmasi Pembayaran Pendaftaran Peserta");
manageFaq.show(fragmentManager, "Konfirmasi");
manageFaq.setData(detailJadwal);
现在我在DialogFragment中从我的ParentActivity调用方法
KonfirmasiPembayaranPesertaFragment curFrag = (KonfirmasiPembayaranPesertaFragment)
getSupportFragmentManager().findFragmentByTag("Konfirmasi");
if(curFrag!=null && curFrag.getDialog()!=null
&& curFrag.getDialog().isShowing()) {
// call method
} else {
// DialogFragment not detect
}
问题:curFrag为null,那么如何解决呢?
答案 0 :(得分:0)
Fragment curFrag = getFragmentManager().findFragmentByTag("Konfirmasi");
if (curFrag != null) {
FragmentTransaction removeTransaction = getFragmentManager().beginTransaction();
removeTransaction.remove(prev);
removeTransaction.commit();
}
// Create and show the dialog Fragment.
if(curFrag ==null){
curFrag = new KonfirmasiPembayaranPesertaFragment ();
}
curFrag.show(getFragmentManager(),"Konfirmasi");
}