Example usage for android.app AlertDialog.Builder show

List of usage examples for android.app AlertDialog.Builder show

Introduction

In this page you can find the example usage for android.app AlertDialog.Builder show.

Prototype

public void show() 

Source Link

Document

Start the dialog and display it on screen.

Usage

From source file:Main.java

public static void showDialog(Context context, String title, String message, String buttonText,
        DialogInterface.OnClickListener buttonClickListener) {
    AlertDialog.Builder dlg = new AlertDialog.Builder(context);
    dlg.setTitle(title);//from  ww  w  .j  a  v a 2s .c o m
    dlg.setMessage(message);
    dlg.setCancelable(false);
    dlg.setPositiveButton(buttonText, buttonClickListener);
    dlg.create();
    dlg.show();
}

From source file:Main.java

/**
 * Shows an alert dialog with OK button//  w w  w. j  a  va 2  s.com
 *
 */
public static void showAlertDialog(Context ctx, String title, String body,
        DialogInterface.OnClickListener okListener) {

    if (okListener == null) {
        okListener = new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        };
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(ctx).setMessage(body).setPositiveButton("OK",
            okListener);

    if (!TextUtils.isEmpty(title)) {
        builder.setTitle(title);
    }

    builder.show();
}

From source file:Main.java

public static void showMessage(Context _context, String title, String message, int icon,
        DialogInterface.OnClickListener ackHandler) {
    AlertDialog.Builder builder = new AlertDialog.Builder(_context);
    builder.setTitle(title);/*  ww  w. j a v a 2 s.co m*/
    builder.setMessage(Html.fromHtml(message));
    builder.setCancelable(false);
    builder.setPositiveButton("Acknowledged", ackHandler);
    builder.setIcon(icon);
    builder.show();
}

From source file:Main.java

/**
 * Shows the status in Dialog./*w ww.  j  a v a 2s .  c  o  m*/
 * 
 * @param context
 * @param message
 */
public static void showStatus(Activity activity, String message, String title) {
    AlertDialog.Builder dialog = new AlertDialog.Builder(activity);
    dialog.setCancelable(false);
    dialog.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
        }
    });
    dialog.show();
}

From source file:Main.java

public static void showChangelog(final Context context, final String title, final String appname,
        final int resChanges, final int resNotes) {
    final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(context);
    final String v0 = p.getString(PREFS_LAST_RUN, "");
    String v1 = null;// w w  w .j a  v a 2  s .com
    try {
        v1 = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
    } catch (NameNotFoundException e) {
        Log.e(TAG, "package not found: " + context.getPackageName(), e);
    }
    p.edit().putString(PREFS_LAST_RUN, v1).commit();
    if (v0.length() == 0) {
        Log.d(TAG, "first boot, skip changelog");
        // return;
    }
    if (v0.equals(v1)) {
        Log.d(TAG, "no changes");
        return;
    }

    String[] changes = context.getResources().getStringArray(resChanges);
    String[] notes = resNotes > 0 ? context.getResources().getStringArray(resNotes) : null;

    final SpannableStringBuilder sb = new SpannableStringBuilder();
    for (String s : notes) {
        SpannableString ss = new SpannableString(s + "\n");
        int j = s.indexOf(":");
        if (j > 0) {
            if (!TextUtils.isEmpty(s)) {
                ss.setSpan(new StyleSpan(Typeface.BOLD), 0, j, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        }
        sb.append(ss);
        sb.append("\n");
    }
    if (notes != null && notes.length > 0) {
        sb.append("\n");
    }
    for (String s : changes) {
        s = appname + " " + s.replaceFirst(": ", ":\n* ").replaceAll(", ", "\n* ") + "\n";
        SpannableString ss = new SpannableString(s);
        int j = s.indexOf(":");
        if (j > 0) {
            ss.setSpan(new StyleSpan(Typeface.BOLD), 0, j, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        sb.append(ss);
        sb.append("\n");
    }
    sb.setSpan(new RelativeSizeSpan(0.75f), 0, sb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    changes = null;
    notes = null;

    AlertDialog.Builder b = new AlertDialog.Builder(context);
    b.setTitle(title);
    b.setMessage(sb);
    b.setCancelable(true);
    b.setPositiveButton(android.R.string.ok, null);
    b.show();
}

From source file:Main.java

public static void showDialogBox(Context context, String title, String msg, int icon) {
    AlertDialog.Builder ad = new AlertDialog.Builder(context);
    ad.setTitle(title);/*from   w  w w. j  a v a2s .co  m*/
    ad.setPositiveButton(android.R.string.ok, null);
    if (icon <= 0)
        ad.setIcon(android.R.drawable.ic_dialog_alert);
    else
        ad.setIcon(icon);
    ad.setMessage(msg);
    ad.show();
}

From source file:Main.java

public static void showMessage(Context _context, String title, String message, int icon,
        DialogInterface.OnClickListener ackHandler) {
    try {//from ww  w.  j ava 2s .c  o m
        AlertDialog.Builder builder = new AlertDialog.Builder(_context);
        builder.setTitle(title);
        builder.setMessage(Html.fromHtml(message));
        builder.setCancelable(false);
        builder.setPositiveButton("Acknowledged", ackHandler);
        builder.setIcon(icon);
        builder.show();
    } catch (Exception e) {
    }
}

From source file:Main.java

/**
 * Shows the status in Dialog.//w  w  w .  ja  va  2s.c om
 * 
 * @param context
 * @param message
 */
public static void showStatus(Activity activity, String message, String title) {
    android.app.AlertDialog.Builder dialog = new android.app.AlertDialog.Builder(activity);
    dialog.setCancelable(false);
    dialog.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
        }
    });
    dialog.show();
}

From source file:Main.java

public static void createAlert(String errorTitle, String errorMessage, Context ctx) {
    AlertDialog.Builder dialog = new AlertDialog.Builder(ctx);
    dialog.setTitle(errorTitle);// www  .java 2s. c o  m
    dialog.setMessage(errorMessage);
    dialog.setPositiveButton("Close", new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface arg0, int arg1) {
            return;
        }
    });
    dialog.show();
}

From source file:Main.java

public static void showYesNoPrompt(Context _context, String title, String message,
        OnClickListener onYesListener, OnClickListener onNoListener) {
    AlertDialog.Builder builder = new AlertDialog.Builder(_context);
    builder.setTitle(title);/*from w w  w .j ava 2  s.  c  om*/
    builder.setIcon(android.R.drawable.ic_dialog_info); // lame icon
    builder.setMessage(message);
    builder.setCancelable(false);
    builder.setPositiveButton("Yes", onYesListener);
    builder.setNegativeButton("No", onNoListener);
    builder.show();
}