java - Call AlertDialog from another class -
i have decided place dialogs in notify class.
however when attempt call dialog, application crashes
this notify class:
public class notify extends activity { public void errorhandler(string title, exception e) { eh(title, e); } public void messagebox(string title, string details) { alertdialog(title, details); } //*************************************************************** //display error dialog. //**************************************************************** private void eh(string method, exception e) { log.e("firstdroid exception", method + " : " + e.getmessage()); e.printstacktrace(); alertdialog alertdialog; alertdialog = new alertdialog.builder(this).create(); alertdialog.settitle(method); alertdialog.setmessage(e.getmessage()); alertdialog.seticon(r.drawable.quiticon); alertdialog.setcanceledontouchoutside(true); alertdialog.show(); } //************************************************************* //generic dialog messages user //************************************************************* private void alertdialog(string title, string message) { log.i("message", message); alertdialog.builder messagebox; messagebox = new alertdialog.builder(null); messagebox.settitle(title); messagebox.setmessage(message); messagebox.seticon(r.drawable.infoicon); messagebox.setneutralbutton("ok", null); messagebox.setcancelable(false); messagebox.show(); }
i create new instance of notify, , call messagebox, so:
notify notify = new notify(); notify.messagebox("test title", "test message");
android.app.alertdialog.builder.builder(context context), u need transfer or applicationcontext eh() method,
alertdialog = new alertdialog.builder(this).create();
for another, why u create 1 activity , call public method? what's meaning, hava no idea it.
Comments
Post a Comment