Android examples for User Interface:Alert Dialog
show Alert with Android default Icon
//package com.java2s; import android.app.AlertDialog; import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; public class Main { public static void showAlert(Context context, int titleId, int messageId) { Dialog dlg = new AlertDialog.Builder(context) .setIcon(android.R.drawable.ic_dialog_alert) .setTitle(titleId)//from www. j a v a 2 s . co m .setPositiveButton(android.R.string.ok, null) .setMessage(messageId).create(); dlg.show(); } public static void showAlert(Context context, int titleId, int messageId, CharSequence positiveButtontxt, DialogInterface.OnClickListener positiveListener, CharSequence negativeButtontxt, DialogInterface.OnClickListener negativeListener) { Dialog dlg = new AlertDialog.Builder(context) // .setIcon(android.R.drawable.ic_dialog_alert) .setTitle(titleId) .setPositiveButton(positiveButtontxt, positiveListener) .setNegativeButton(negativeButtontxt, negativeListener) .setMessage(messageId).setCancelable(false).create(); dlg.show(); } public static void showAlert(Context context, int titleId, int messageId, CharSequence positiveButtontxt, DialogInterface.OnClickListener positiveListener) { Dialog dlg = new AlertDialog.Builder(context) .setIcon(android.R.drawable.ic_dialog_alert) .setTitle(titleId) .setPositiveButton(positiveButtontxt, positiveListener) .setMessage(messageId).setCancelable(false).create(); dlg.show(); } }