Peter Sankauskas Peter Sankauskas - 9 months ago 45
Android Question

What's the best was to have reusable dialog boxes?

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

Reading through the Dialog dev guide, I know I can use

in one of my
s, 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

Any suggestions?


Crate one class file like as and add this code in that class file.

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

and you can use from any class like as