Generic ManagedAlert Dialog

GenericManagedAlertDialog is the alert-dialog implementation; it extends ManagedActivityDialog. This class is responsible for creating the actual alert dialog using the alert-dialog builder. It also carries all the information it needs as local variables. Because GenericManagedAlertDialog implements a simple alert dialog, it does nothing in the onClickHook method. The key thing to note is that when you use this approach, GenericManagedAlertDialog encapsulates all pertinent information in one place (see Listing 5-33). That keeps the mainline code in the activity squeaky-clean.

Listing 5-33. The GenericManagedAlertDialog Class public class GenericManagedAlertDialog extends ManagedActivityDialog {

private String alertMessage = null; private Context ctx = null;

public GenericManagedAlertDialog(ManagedDialogsActivity inActivity, int dialogId, String initialMessage)

super(inActivity,dialogId); alertMessage = initialMessage; ctx = inActivity;

public Dialog create() {

AlertDialog.Builder builder = new AlertDialog.Builder(ctx);

builder. setTitle("Alert");


builder.setPositiveButton("Ok", this );

AlertDialog ad = builder.create();

return ad;

public void prepare(Dialog dialog) {

AlertDialog ad = (AlertDialog)dialog; ad.setMessage(alertMessage);

public void setAlertMessage(String inAlertMessage) {

alertMessage = inAlertMessage;

public void onClickHook(int buttonId) {

//nothing to do

//no local variables to set

0 0

Post a comment