Android examples for User Interface:Dialog
Display a standard Ok 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; /**/* ww w. ja v a2s .c o m*/ * Display a standard Ok dialog. * * @param context * The current context. * @param icon * The dialog icon. * @param title * The dialog title. * @param message * The dialog message. */ public static void showOkDialog(Context context, int icon, String title, String message) { String packagename = context.getPackageName(); AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setCancelable(false); builder.setIcon(icon); builder.setTitle(title); builder.setMessage(message); builder.setInverseBackgroundForced(true); builder.setPositiveButton( getResId("string", "browser_Commons_Ok", packagename), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); 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); } }