manage Alert Dialog - Android User Interface

Android examples for User Interface:Alert Dialog

Description

manage Alert Dialog

Demo Code


//package com.java2s;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;

public class Main {
    public static final String OK = "OK";

    public static Runnable manageAlertDialog(
            final Activity fourerrActivity, final String dialogTitle,
            final String dialogMessage) {

        return new Runnable() {

            public void run() {
                final AlertDialog alertDialog = buildAlertDialog(
                        dialogTitle, dialogMessage);
                alertDialog.show();/*from  ww  w  . jav a 2s  .c o  m*/
            }

            private AlertDialog buildAlertDialog(final String dialogTitle,
                    final String dialogMessage) {

                final AlertDialog alertDialog = new AlertDialog.Builder(
                        fourerrActivity).create();
                alertDialog.setTitle(dialogTitle);
                alertDialog.setMessage(dialogMessage);
                alertDialog.setButton(OK,
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                    int which) {
                                fourerrActivity
                                        .setResult(Activity.RESULT_OK);
                                fourerrActivity.finish();
                                return;
                            }
                        });

                return alertDialog;

            }
        };
    }
}

Related Tutorials