android - Cannot show a dialogfragment within a fragment -
i have fragment, layout has button, , add click listener it, on onclick executes this:
cfrag_fe_datepicker dp = new cfrag_fe_datepicker(); dp.show(getfragmentmanager(), "dp");
where cfrag_fe_datepicker dialogframent
however, fragment didn't pop up. set breakpoint inside onclick proc, breaks expected, , happily goes past dp.show() nothing happens.
i move button activity time works without problems.
why so?
here source of fragment, sorry if there many irrelevant codings here:
package com.prime.no2_andr; import java.util.locale; import android.os.bundle; import android.os.handler; import android.app.dialogfragment; import android.app.fragment; import android.app.fragmenttransaction; import android.support.v4.app.fragmentmanager; import android.support.v4.app.fragmentpageradapter; import android.support.v4.view.viewpager; import android.view.layoutinflater; import android.view.view; import android.view.view.onclicklistener; import android.view.viewgroup; import android.widget.textview; public class cfrag_fe_datepicker extends dialogfragment implements onclicklistener{ viewpager mviewpager; boolean isshowcal = true; cfrag_dp fragdp = new cfrag_dp(); cfrag_cal fragcal = new cfrag_cal(); private final handler handler = new handler(); private runnable runpager; boolean isloaded = false; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); // sectpageradp = new sectionspageradapter(getfragmentmanager()); // mviewpager = (viewpager) getview().findviewbyid(r.id.pager); // mviewpager.setadapter(sectpageradp); } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { // inflate layout fragment view v = inflater.inflate(r.layout.frag_fe_datepicker, container, false); v.findviewbyid(r.id.btn_more).setonclicklistener(this); return v; } @override public void onactivitycreated(bundle savedinstancestate) { super.onactivitycreated(savedinstancestate); if (isloaded) return; // isloaded = true; // runpager = new runnable() { // // @override // public void run() //// { // getfragmentmanager().begintransaction().add(r.id.rl_cont, fragdp).commit(); // } // }; // handler.post(runpager); } /** * @see android.support.v4.app.fragment#onpause() */ @override public void onpause() { super.onpause(); // handler.removecallbacks(runpager); } public void onclickmore(view btn) { } public fragmenttransaction execaddfrag(fragmenttransaction ft){ ft.add(r.id.rl_cont, //fragdp fragcal ); return ft; } public static class cfrag_dp extends cfrag_dp_cal { public cfrag_dp() { super(false); } } public static class cfrag_cal extends cfrag_dp_cal { public cfrag_cal() { super(true); } } public static abstract class cfrag_dp_cal extends fragment { boolean iscal; public cfrag_dp_cal(boolean in_iscal) { iscal = in_iscal; } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { // inflate layout fragment return inflater.inflate( iscal? r.layout.frag_fe_datepicker_cal : r.layout.frag_fe_datepicker_dp, container, false); } } @override public void onclick(view v) { isshowcal = !isshowcal; /* getfragmentmanager().begintransaction() .replace(r.id.rl_cont, isshowcal? fragcal : fragdp) .commitallowingstateloss(); */ // ((textview)getview().findviewbyid(r.id.textview1)).settext(isshowcal? "t":"f"); } }
if using nested fragments , call getfragmentmanager() on child fragment, fragmentmanager returned parent's getchildfragmentmanager() not hosting activity's fragmentmanager. try calling getactivity().getfragmentmanager()
if that's case.
Comments
Post a Comment