对于整个应用程序单警告对话框 [英] Single alert dialog for entire application

查看:152
本文介绍了对于整个应用程序单警告对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要在我的应用程序显示许多错误消息和警报对话。 我不想用吐司,但我preFER使用ALertDialog。

I have to display many error messages and alert dialogues in my application. I do not want to use Toast but i prefer to use ALertDialog.

无论活动我在,我必须能够访问警报对话框实例,显示并关闭它。

Whatever activity I am in,I must be able to access the alert dialog instance and show and dismiss it.

我怎样才能做到这一点? 请给我一些这方面的领先优势。

How can i achieve this ? Kindly give me some lead on this.

推荐答案

让一个类和粘贴功能...(可能是Utils.java)

make one class and paste this function...(may be Utils.java)

public static void alertDialogShow(Context context, String message)
        {
            final AlertDialog alertDialog = new AlertDialog.Builder(context).create();
            alertDialog.setMessage(message);
            alertDialog.setButton("OK", new DialogInterface.OnClickListener() 
            {
                public void onClick(DialogInterface dialog, int which) 
                {
                    alertDialog.dismiss();
              } 
            }); 
            alertDialog.show();
        }

和写调用此。

Utils.alertDialogShow(YourActivity.this,"Your Error Message")

这篇关于对于整个应用程序单警告对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆