android单例对话框 [英] android singleton dialog

查看:53
本文介绍了android单例对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个处理大量进度对话框的 android 应用程序.我必须为每个活动创建一个单独的对话框.

I have android application which deals with lot of progress dialogs.I have to create a separate dialog for each activity.

对话框创建在构造时将活动(上下文)作为参数.

Dialog creation takes a activity(context) as parameter while constructing.

有没有一种方法可以创建单个对话框(与应用程序而非活动相关联)并在不同的活动中显示它,这样我就不必重复创建它.

Is there a way by which I can create a single dialog (which is tied to application and not the activity) and show it in different activity so that I do not have to create it repeatedly.

推荐答案

在 Utill helper 类中声明 showProgressDialoghideProgressDialog,如下面的代码片段

Declare showProgressDialog and hideProgressDialog in Utill helper class as shown in following code snippet

public static ProgressDialog showProgressDialog(Context context) {
        ProgressDialog pDialog = new ProgressDialog(context);
        pDialog.setMessage("Please wait...");
        pDialog.setCancelable(false);
        pDialog.show();
        return pDialog;
    }

    public static void hideProgressDialog(ProgressDialog pDialog) {
        if (pDialog.isShowing())
            pDialog.dismiss();
    }

然后从您需要显示 ProgressDialog 的活动中调用,例如在 AsyncTask 类的 onPreExecute() 方法中,如下面的代码片段

Then call from activity where you need to show the ProgressDialog for example in onPreExecute() method of AsyncTask class as shown in below code snippet

ProgressDialog pDialog = Util.showProgressDialog(this);

并使用以下代码隐藏progressDialog

and use following code to hide the progressDialog

 Util.hideProgressDialog(pDialog);

这篇关于android单例对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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