Android examples for User Interface:Alert Dialog
show Alert Dialog
//package com.java2s; import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; public class Main { public static final OnClickListener emptyDialogOnClickListener = new OnClickListener() { @Override//from ww w .java2 s.com public void onClick(DialogInterface arg0, int arg1) { } }; public static void showAlertDialog(Activity activity, int icon, int title, int message, boolean afterFinish) { new AlertDialog.Builder(activity) .setIcon(icon) .setTitle(title) .setMessage(message) .setPositiveButton( android.R.string.ok, afterFinish ? getFinishDialogOnClickListener(activity) : emptyDialogOnClickListener).show(); } public static void showAlertDialog(Activity activity, int icon, int title, CharSequence message, boolean afterFinish) { new AlertDialog.Builder(activity) .setIcon(icon) .setTitle(title) .setMessage(message) .setPositiveButton( android.R.string.ok, afterFinish ? getFinishDialogOnClickListener(activity) : emptyDialogOnClickListener).show(); } public static OnClickListener getFinishDialogOnClickListener( final Activity activity) { return new OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { activity.finish(); } }; } }