display Alert dialog with OK button - Android User Interface

Android examples for User Interface:Alert Dialog

Description

display Alert dialog with OK button

Demo Code


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

public class Main {
    public static final String OK = "OK";
    private static final DialogInterface.OnClickListener DISMISSER = new DialogInterface.OnClickListener() {

        @Override/*from w ww. j a v  a  2  s .  com*/
        public void onClick(DialogInterface dialog, int which) {

            dialog.dismiss();
        }
    };

    public static void displayAlertOK(Context context, String alertTitle,
            String alertMessage) {

        displayAlertOK(context, alertTitle, alertMessage, DISMISSER);
    }

    public static void displayAlertOK(Context context, String alertTitle,
            String alertMessage, DialogInterface.OnClickListener okListener) {

        AlertDialog alertDialog = new AlertDialog.Builder(context).create();
        alertDialog.setTitle(alertTitle);
        alertDialog.setMessage(alertMessage);
        alertDialog.setButton(DialogInterface.BUTTON_NEUTRAL, OK,
                okListener);
        alertDialog.show();
    }
}

Related Tutorials