Android examples for User Interface:Dialog
Display a continue / cancel dialog.
//package com.java2s; import java.lang.reflect.Field; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; public class Main { private static String mPackageName = null; /**/* w w w .j av a2 s. co m*/ * Display a continue / cancel dialog. * * @param context * The current context. * @param icon * The dialog icon. * @param title * The dialog title. * @param message * The dialog message. * @param onContinue * The dialog listener for the continue button. * @param onCancel * The dialog listener for the cancel button. */ public static void showContinueCancelDialog(Context context, int icon, String title, String message, DialogInterface.OnClickListener onContinue, DialogInterface.OnClickListener onCancel) { String packagename = context.getPackageName(); AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setCancelable(true); builder.setIcon(icon); builder.setTitle(title); builder.setMessage(message); builder.setInverseBackgroundForced(true); builder.setPositiveButton( getResId("string", "browser_Commons_Continue", packagename), onContinue); builder.setNegativeButton( getResId("string", "browser_Commons_Cancel", packagename), onCancel); AlertDialog alert = builder.create(); alert.show(); } public static Integer getResId(String rType, String rName, String packagename) { Object localObject = null; ; try { Class localClass = Class.forName(packagename + ".R" + "$" + rType); Field localField = localClass.getField(rName); localObject = localField.get(localClass.newInstance()); } catch (Exception localException) { localException.printStackTrace(); } return Integer.valueOf(Integer.parseInt(localObject.toString())); } public static Integer getResId(String rType, String rName) { return getResId(rType, rName, mPackageName); } }