什么是最好的是有可重复使用的对话框? [英] What's the best was to have reusable dialog boxes?

查看:193
本文介绍了什么是最好的是有可重复使用的对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是最好的是Android的创建可重用的对话框?

What's the best was to create reusable dialog boxes in Android?

通过对话框开发指南阅读,我知道我可以使用 AlertDialog.Builder(本); 在我的活动之一 S,但是如果我想在多个使用这个什么活动?如果这是一些其他的I类将扩展它,所以 MyDialog延伸AlertDialog ,但我不能使用生成器

Reading through the Dialog dev guide, I know I can use AlertDialog.Builder(this); in one of my Activitys, but what if I want to use this in multiple Activities? If this was some other class I would extend it, so MyDialog extends AlertDialog, but then I cannot use the Builder.

有什么建议?

推荐答案

您好,

箱子一个类文件等作为allmethod.java

crate one class file like as allmethod.java

和在类中添加这个code

and add this code in that class

public static void showAlert(Activity act,String msg)
        {
            AlertDialog.Builder alert = new AlertDialog.Builder(act);
            alert.setMessage(msg).setPositiveButton("OK", new OnClickListener(){
                @Override
                public void onClick(DialogInterface dialog, int which)
                {   
                }
            }).show();
        }

,你可以从任何类使用类似的

and you can use from any class like as

allmethod.showAlert(Activity,"Message");

这篇关于什么是最好的是有可重复使用的对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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