java - Android - Show Dialog from static class -
i have simple class want use show dialog message:
public class utils { static void showmessage(context c, string dialogtitle, string messagetodisplay, int layoutresourceid, int imageresourceid ){ //create new dialog. dialog dialog = new dialog(c); //set view existing xml layout. dialog.setcontentview(layoutresourceid); dialog.settitle(dialogtitle); //set textbox text , icon dialog. textview text = (textview) dialog.findviewbyid(r.id.text); text.settext(messagetodisplay); imageview image = (imageview)dialog.findviewbyid(r.id.image); image.setimageresource(imageresourceid); //show dialog window. dialog.show(); } }
and trying call activity, within onclicklistener event of button, so:
private onclicklistener btnsubmitissueclick = new onclicklistener(){ public void onclick(view v){ //check valid summary & description. if(msummaryedittext.gettext().tostring().trim().length() == 0){ utils.showmessage(getbasecontext(), "submit issue error", getbasecontext().getstring(r.string.error_summaryrequired), r.layout.modal_dialog, r.drawable.warning); return; }else if(mdescriptionedittext.gettext().tostring().trim().length() == 0){ utils.showmessage(getbasecontext(), "submit issue error", getbasecontext().getstring(r.string.error_descriptionrequired), r.layout.modal_dialog, r.drawable.warning); return; } } };
but when run it, error:
03-07 16:56:00.290: w/windowmanager(169): attempted add window non-application token windowtoken{4162e780 token=null}. aborting.
any ideas doing wrong?
you're passing in base context context used create dialog. needs context activity hosting dialog. activity context object can pass in reference activity.
the following question here gives more complete explanation.
Comments
Post a Comment