Android examples for User Interface:Alert Dialog
show Alert and add click listener for OK button
//package com.java2s; import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; public class Main { public static void showAlert(Activity act, String title, String msg) { AlertDialog dialog = new AlertDialog.Builder(act).create(); dialog.setCancelable(true);// w ww. j a va 2 s . co m if (title != null) dialog.setTitle(title); if (msg != null) dialog.setMessage(msg); dialog.setButton("Ok", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); dialog.show(); } }