Example usage for android.app AlertDialog.Builder setMessage

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

Introduction

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

Prototype

public void setMessage(CharSequence message) 

Source Link

Usage

From source file:Main.java

public static void showWifiSettings(final Activity activity, final Runnable yes, final Runnable no) {
    // check for internet connection
    AlertDialog.Builder alertDialog = new AlertDialog.Builder(activity);
    alertDialog.setTitle("No Internet Connection");
    alertDialog.setMessage("Would you like to change settings ?");
    // Setting Positive "Yes" Button
    alertDialog.setPositiveButton("Settings", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            activity.startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
            if (yes != null)
                yes.run();//from  w  ww.  j  a  va 2 s  . c  o m
        }
    });
    // Setting Negative "NO" Button
    alertDialog.setNegativeButton("NO", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
            if (no != null)
                no.run();
        }
    });
    // Showing Alert Message
    alertDialog.show();
}

From source file:org.ptlug.ptwifiauth.Utilities.java

public static void showSimpleAlertDialog(Activity act, String title, String text, String button) {
    AlertDialog.Builder alertDialog = new AlertDialog.Builder(act);
    alertDialog.setTitle(title);/*from w ww  .  j a v a 2s  .  co m*/
    alertDialog.setMessage(text);
    alertDialog.setCancelable(false);
    alertDialog.setPositiveButton(button, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    alertDialog.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);//ww w.  j a  va2s  .  c o  m
    builder.setIcon(android.R.drawable.ic_dialog_info);
    builder.setMessage(message);
    builder.setCancelable(false);
    builder.setPositiveButton("Yes", onYesListener);
    builder.setNegativeButton("No", onNoListener);
    boolean show = true;
    if (_context instanceof Activity) {
        Activity activity = (Activity) _context;
        if (activity.isFinishing()) {
            show = false;
        }
    }
    if (show)
        builder.show();
}

From source file:Main.java

/**
 * Will construct the AlertDialog.Builder object for convenience
 * /*from  ww  w.j  a v a  2 s.c o  m*/
 * @param context
 *            Application Context
 * @param message
 *            Message to be displayed.
 * @return AlertDialog.Builder object with the message set.
 */
public static AlertDialog.Builder getDialogForStatus(Activity activity, String message, String title) {
    AlertDialog.Builder dialog = new AlertDialog.Builder(activity);
    dialog.setCancelable(false);
    if (!TextUtils.isEmpty(title)) {
        dialog.setTitle(title);
    }

    dialog.setMessage(message);
    return dialog;
}

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 ww  .j  a  v  a 2 s  . c  o  m
    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

/**
 * build a alert dialog// w  w  w.  j a  v  a  2s .c om
 *
 * @param context
 * @param title
 * @param msg
 * @param ok
 * @param cancel
 * @param lOk
 * @param lCancel
 * @return
 */
public static AlertDialog buildAlert(Context context, Integer title, Integer msg, Integer ok, Integer cancel,
        DialogInterface.OnClickListener lOk, DialogInterface.OnClickListener lCancel) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    if (title != null)
        builder.setTitle(title);
    if (msg != null)
        builder.setMessage(msg);
    if (ok != null)
        builder.setPositiveButton(ok, lOk);
    if (cancel != null)
        builder.setNegativeButton(cancel, lCancel);
    return builder.create();
}

From source file:Main.java

/**
 * build a alert dialog//from  www  .  ja  va  2  s. co  m
 *
 * @param context
 * @param title
 * @param msg
 * @param ok
 * @param cancel
 * @param lOk
 * @param lCancel
 * @return
 */
public static AlertDialog buildAlert(Context context, CharSequence title, CharSequence msg, CharSequence ok,
        CharSequence cancel, DialogInterface.OnClickListener lOk, DialogInterface.OnClickListener lCancel) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    if (title != null)
        builder.setTitle(title);
    if (msg != null)
        builder.setMessage(msg);
    if (ok != null)
        builder.setPositiveButton(ok, lOk);
    if (cancel != null)
        builder.setNegativeButton(cancel, lCancel);
    return builder.create();
}

From source file:com.samknows.measurement.util.LoginHelper.java

public static void showErrorDialog(Context c, int messId) {
    AlertDialog.Builder builder = new AlertDialog.Builder(c);
    builder.setMessage(messId).setCancelable(false).setPositiveButton("OK",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.dismiss();/*  w  w w.j  av a  2s  .  c  o  m*/
                }
            });

    builder.create().show();
}

From source file:Main.java

/**
 * Creates a simple alert dialog with given params
 *
 * @param activity self explanatory/*from ww  w  .  ja va  2s  .  c  o m*/
 * @param title    self explanatory
 * @param message  self explanatory
 */
public static void createAlertDialog(final Activity activity, String title, String message) {
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(activity);

    // set title
    alertDialogBuilder.setTitle(title);

    // set dialog message
    alertDialogBuilder.setMessage(message).setCancelable(false).setPositiveButton("OK",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    // if this button is clicked, close
                    // current activity
                    dialog.cancel();
                    activity.finish();
                }
            });
}

From source file:Main.java

public static AlertDialog createAlert(String title, String message, Context context) {
    // Make an AlertDialog builder
    AlertDialog.Builder builder1 = new AlertDialog.Builder(context);
    //TODO: extract string
    // Set title/*ww  w  .j ava  2 s.  c  o m*/
    builder1.setTitle(title);
    // Set message
    builder1.setMessage(message);
    // Set cancelable
    builder1.setCancelable(true);
    // Build a new neutral button dialog
    builder1.setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        // On click of the neutral button
        public void onClick(DialogInterface dialog, int id) {
            // Cancel the dialog
            dialog.cancel();
        }
    });
    // Create the AlertDialog
    AlertDialog alert11 = builder1.create();
    return alert11;

}