Java tutorial
//package com.java2s; //License from project: Open Source License import android.app.Activity; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; public class Main { private static int retValue = -1; private static AlertDialog alert = null; public static void DisplayAlertOKCancel(final Context context, final String title, final String message) { retValue = -1; final Activity activity = (Activity) context; activity.runOnUiThread(new Runnable() { @Override public void run() { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setMessage(message); builder.setTitle(title); builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { retValue = 1; alert = null; } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { retValue = 0; alert = null; } }); alert = builder.create(); alert.show(); } }); } }