Example usage for android.app AlertDialog setButton

List of usage examples for android.app AlertDialog setButton

Introduction

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

Prototype

public void setButton(int whichButton, CharSequence text, OnClickListener listener) 

Source Link

Document

Set a listener to be invoked when the positive button of the dialog is pressed.

Usage

From source file:Main.java

public static void showAlert(String msg, Context context) {
    AlertDialog alertDialog = new AlertDialog.Builder(context).create();
    alertDialog.setTitle("Alert");
    alertDialog.setMessage(msg);/*from  ww w. j a va 2 s. com*/
    alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    alertDialog.show();
}

From source file:Main.java

public static void showAlertDialog(Context ctx, String title, String message) {

    AlertDialog alertDialog = new AlertDialog.Builder(ctx).create();
    alertDialog.setTitle(title);//from ww w  .  j a va 2s.com
    alertDialog.setMessage(message);

    alertDialog.setButton(DialogInterface.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {

        }
    });
    alertDialog.show();
}

From source file:Main.java

public static AlertDialog showAlertMessage(String title, String message, Context context) {
    final AlertDialog alertDialog = new AlertDialog.Builder(context).create();
    alertDialog.setTitle(title);/*w ww.  j a  va  2 s  . c om*/
    alertDialog.setMessage(message);
    alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            alertDialog.dismiss();
        }
    });
    alertDialog.show();
    return alertDialog;
}

From source file:Main.java

public static void showMessage(String message, Context context) {
    AlertDialog alertDialog = new AlertDialog.Builder(context).create();
    alertDialog.setTitle("New Message");
    alertDialog.setMessage(message);/*from w  w w . ja v  a 2s  .c o m*/
    alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    alertDialog.show();
}

From source file:Main.java

static public void showAlert(Context ctx, final String message) {
    AlertDialog alertDialog = new AlertDialog.Builder(ctx).create();
    alertDialog.setTitle("Application Error");
    alertDialog.setMessage(message);//  ww w  . j  av a2  s . co  m
    alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "Dismiss", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            // Do nothing
        }
    });
    alertDialog.show();
}

From source file:Main.java

public static void showAlertDialog(Context context, String title, String message) {
    AlertDialog dialog = new AlertDialog.Builder(context).create();
    dialog.setCancelable(true);//from  w ww  . ja  v  a2 s . c om
    dialog.setMessage(message);
    dialog.setTitle(title);
    dialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });
    dialog.show();
}

From source file:org.cocos2dx.cpp.AppActivity.java

public static void onQuitDialogShow() {
    AlertDialog.Builder builder = new Builder(getContext());
    AlertDialog dialog = builder.create();
    dialog.setTitle("??");
    dialog.setButton(AlertDialog.BUTTON_POSITIVE, "", new DialogInterface.OnClickListener() {

        @Override//from w w w.  ja v  a2  s . c o m
        public void onClick(DialogInterface arg0, int arg1) {
            System.exit(0);
        }
    });
    dialog.setButton(AlertDialog.BUTTON_NEGATIVE, "?", new DialogInterface.OnClickListener() {

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

From source file:com.crea_si.eviacam.wizard.WizardUtils.java

static void checkEngineAndFinishIfNeeded(final Activity a) {
    AccessibilityServiceModeEngine engine = MainEngine.getAccessibilityServiceModeEngine();
    if (engine == null || !engine.isReady()) {
        // Engine is not ready anymore
        final Resources res = a.getResources();
        AlertDialog ad = new AlertDialog.Builder(a).create();
        ad.setCancelable(false); // This blocks the 'BACK' button
        ad.setTitle(res.getText(R.string.eva_not_running));
        ad.setMessage(res.getText(R.string.eva_not_running_summary));
        ad.setButton(DialogInterface.BUTTON_NEUTRAL, res.getText(R.string.close),
                new DialogInterface.OnClickListener() {
                    @Override/*from w  w w  .  j  a va  2  s  .com*/
                    public void onClick(DialogInterface dialog, int which) {
                        finishWizard(a);
                    }
                });
        ad.show();
    }
}

From source file:com.streaming.sweetplayer.utils.Utils.java

/**
 * Function to show a dialog to the user about a current problem or inform about something happening.
 *
 * @param context Context/*w w w.ja  va2  s  .  c o  m*/
 * @param title   String
 * @param message String
 */
public static void showAlertDialog(Context context, String title, String message) {
    AlertDialog alertDialog = new AlertDialog.Builder(context).create();
    alertDialog.setTitle(title);
    alertDialog.setMessage(message);
    alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
        }
    });
    alertDialog.show();
}

From source file:com.eleybourn.bookcatalogue.dialogs.StandardDialogs.java

public static void needLibraryThingAlert(final Context context, final boolean ltRequired,
        final String prefSuffix) {
    boolean showAlert;
    int msgId;/* w  w w . j a  v  a2 s . c  o m*/
    final String prefName = LibraryThingManager.LT_HIDE_ALERT_PREF_NAME + "_" + prefSuffix;
    if (!ltRequired) {
        msgId = R.string.uses_library_thing_info;
        SharedPreferences prefs = context.getSharedPreferences("bookCatalogue",
                android.content.Context.MODE_PRIVATE);
        showAlert = !prefs.getBoolean(prefName, false);
    } else {
        msgId = R.string.require_library_thing_info;
        showAlert = true;
    }

    if (!showAlert)
        return;

    final AlertDialog dlg = new AlertDialog.Builder(context).setMessage(msgId).create();

    dlg.setTitle(R.string.reg_library_thing_title);
    dlg.setIcon(android.R.drawable.ic_menu_info_details);

    dlg.setButton(DialogInterface.BUTTON_POSITIVE, context.getResources().getString(R.string.more_info),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    Intent i = new Intent(context, AdministrationLibraryThing.class);
                    context.startActivity(i);
                    dlg.dismiss();
                }
            });

    if (!ltRequired) {
        dlg.setButton(DialogInterface.BUTTON_NEUTRAL,
                context.getResources().getString(R.string.disable_dialogue),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        SharedPreferences prefs = context.getSharedPreferences("bookCatalogue",
                                android.content.Context.MODE_PRIVATE);
                        SharedPreferences.Editor ed = prefs.edit();
                        ed.putBoolean(prefName, true);
                        ed.commit();
                        dlg.dismiss();
                    }
                });
    }

    dlg.setButton(DialogInterface.BUTTON_NEGATIVE, context.getResources().getString(R.string.cancel),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dlg.dismiss();
                }
            });

    dlg.show();
}