android - Showing DialogFragment -
i have class activityexitdialogfragment extends android.support.v4.app.dialogfragment. there 2 methods in activityexitdialogfragment, oncreatedialog , newinstance new instance of activityexitdialogfragment. here are:
public dialog oncreatedialog(bundle savedinstancestate) { string title = getarguments().getstring("title"); dialog mydialog = new alertdialog.builder(getactivity()) .seticon(r.drawable.ic_launcher) .settitle(title) .setnegativebutton("no", new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface dialog, int which) { // dismiss dialog. dismiss(); } }) .setpositivebutton("yes", new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface dialog, int which) { // close activity. getactivity().finish(); } }).create(); return mydialog; } static activityexitdialogfragment newinstance(string message) { activityexitdialogfragment dialog = new activityexitdialogfragment(); bundle args = new bundle(); args.putstring("title", message); dialog.setarguments(args); return dialog; }
and here method used show dialog. in different activity in same package. it's called when user clicks exit button:
public void cancelbutton(view v) { activityexitdialogfragment dialog = activityexitdialogfragment.newinstance(exitmessage); dialog.show(new fragmentactivity().getsupportfragmentmanager(), "exiting"); }
whenever click exit button illegalstateexception @ dialog.show line. had problem before , because didn't have android-support-v4.jar file in libs folder of project. put jar file in libs folder , worked. changed name of class else activityexitdialogfragment , had eclipse change name of java file match. , since i'm getting exception again. dont know if coincidnece got exception again after changing name or if eclipse other change name of jar file match name of public class. have tried changing access modifiers getinstance method, deleting , adding new copy of android support jar file, changing name old name, , have been spending few hours on google have not found answer yet.
you shouldn't try directly instantiate activity new. instead fragment manager directly activity have:
dialog.show(getsupportfragmentmanager(), "exiting");
Comments
Post a Comment