android - setOnCancelListener and setOnDismissListener is not called for AlertDialog for back button pressed or touch outside -
when
- touch outside dialog region
- press on button
i'm expecting ondismiss
(or oncancel
) called. however, both of them not called. may know there i'm missing? alertdialog setondismisslistener not working, thought oncancel
called when press button. doesn't work me. may know there had missed out?
public class rateappdialogfragment extends sherlockdialogfragment { public static rateappdialogfragment newinstance() { rateappdialogfragment rateappdialogfragment = new rateappdialogfragment(); return rateappdialogfragment; } @override public dialog oncreatedialog(bundle savedinstancestate) { // layout inflater layoutinflater inflater = getactivity().getlayoutinflater(); view view = inflater.inflate(r.layout.rate_app_dialog_fragment, null); utils.setcustomtypeface(view, utils.roboto_light_type_face); final alertdialog dialog = new alertdialog.builder(this.getsherlockactivity()) .settitle("love jstock?") .setview(view) // add action buttons .setpositivebutton("rate 5 stars \u2605", new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface dialog, int id) { utils.showshorttoast("rate"); } }) .setnegativebutton("no", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int id) { utils.showshorttoast("no"); } }) .setneutralbutton("later", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int id) { utils.showshorttoast("later"); } }) .create(); dialog.setcanceledontouchoutside(true); dialog.setoncancellistener(new dialoginterface.oncancellistener() { @override public void oncancel(dialoginterface dialog) { utils.showshorttoast("back button pressed?"); } }); dialog.setondismisslistener(new dialoginterface.ondismisslistener() { @override public void ondismiss(dialoginterface dialog) { // todo auto-generated method stub utils.showshorttoast("back button pressed?"); } }); return dialog; } }
fragmentmanager fm = fragmentactivity.getsupportfragmentmanager(); if (fm.findfragmentbytag(rate_app_dialog_fragment) != null) { return; } rateappdialogfragment rateappdialogfragment = rateappdialogfragment.newinstance(); rateappdialogfragment.show(fm, rate_app_dialog_fragment);
the problem happens when using dialogfragment
display dialog
according http://developer.android.com/reference/android/app/dialogfragment.html, solution override oncancel
in dialogfragment
please take note http://developer.android.com/reference/android/app/dialogfragment.html#oncreatedialog(android.os.bundle) too
note: dialogfragment own dialog.setoncancellistener , dialog.setondismisslistener callbacks. must not set them yourself. find out these events, override oncancel(dialoginterface) , ondismiss(dialoginterface).
// dialogfragment, not dialog @override public void oncancel(dialoginterface dialog) { }
Comments
Post a Comment