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:com.eleybourn.bookcatalogue.dialogs.StandardDialogs.java

/**
 * Display a dialog warning the user that goodreads authentication is required; gives them
 * the options: 'request now', 'more info' or 'cancel'.
 *//*www  . j  a va  2s  .  c om*/
public static int goodreadsAuthAlert(final FragmentActivity context) {
    // Get the title      
    final AlertDialog alertDialog = new AlertDialog.Builder(context).setTitle(R.string.authorize_access)
            .setMessage(R.string.goodreads_action_cannot_blah_blah).create();

    alertDialog.setIcon(android.R.drawable.ic_menu_info_details);
    alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, context.getResources().getString(R.string.ok),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    alertDialog.dismiss();
                    GoodreadsRegister.requestAuthorizationInBackground(context);
                }
            });

    alertDialog.setButton(DialogInterface.BUTTON_NEUTRAL,
            context.getResources().getString(R.string.tell_me_more), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    alertDialog.dismiss();
                    Intent i = new Intent(context, GoodreadsRegister.class);
                    context.startActivity(i);
                }
            });

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

    alertDialog.show();
    return 0;

}

From source file:com.hemou.android.account.AccountUtils.java

/**
 * Show conflict message about previously registered authenticator from
 * another application/* ww w .  ja  v a  2 s  .com*/
 * 
 * @param activity
 */
private static void showConflictMessage(final Activity activity) {
    AlertDialog dialog = LightAlertDialog.create(activity);
    dialog.setTitle(activity.getString(string.authenticator_conflict_title));
    dialog.setMessage(activity.getString(string.authenticator_conflict_message));
    dialog.setOnCancelListener(new OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialog) {
            activity.finish();
        }
    });
    dialog.setButton(BUTTON_POSITIVE, activity.getString(android.R.string.ok), new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            activity.finish();
        }
    });
    dialog.show();
}

From source file:com.iStudy.Study.Renren.Util.java

/**
 * ??????/* w w w .j  av a  2  s. c o  m*/
 * 
 * @param activity ?Activity
 * @param title   ?
 * @param text   ?
 * @param listener ?
 */
public static void showOptionWindow(Activity activity, String title, String text, OnOptionListener listener) {
    AlertDialog dialog = new AlertDialog.Builder(activity).create();
    if (title != null) {
        dialog.setTitle(title);
    }

    if (text != null) {
        dialog.setMessage(text);
    }

    final OnOptionListener oListener = listener;
    dialog.setButton(AlertDialog.BUTTON_POSITIVE, activity.getString(R.string.renren_sdk_submit),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    oListener.onOK();
                }
            });
    dialog.setButton(AlertDialog.BUTTON_NEGATIVE, activity.getString(R.string.renren_sdk_cancel),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    oListener.onCancel();
                }
            });
    dialog.show();
}

From source file:org.barbon.mangaget.fragments.ConfirmationDialog.java

private void doSetPositiveClick(AlertDialog dialog) {
    if (dialog == null)
        return;/*from w  w w  .ja  v a 2 s .c o m*/

    int positive = getArguments().getInt("positive");

    dialog.setButton(AlertDialog.BUTTON_POSITIVE, getActivity().getResources().getString(positive),
            positiveClick);
}

From source file:com.github.mobile.ui.ConfirmDialogFragment.java

public Dialog onCreateDialog(final Bundle savedInstanceState) {
    AlertDialog dialog = LightAlertDialog.create(getActivity());
    dialog.setTitle(getTitle());//from  w  ww . ja  v  a  2 s.  c o  m
    dialog.setMessage(getMessage());
    dialog.setButton(BUTTON_POSITIVE, getResources().getString(android.R.string.yes), this);
    dialog.setButton(BUTTON_NEGATIVE, getResources().getString(android.R.string.no), this);
    dialog.setCancelable(true);
    dialog.setOnCancelListener(this);
    return dialog;
}

From source file:fr.android.scaron.diaspdroid.vues.fragment.ParamsFragment.java

@UiThread
public void showResultLogin(boolean loginOK) {
    String methodName = ".showResultLogin : ";
    LOG.d(methodName + "Entre");
    if (loginOK) {
        final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                DiasporaConfig.APPLICATION_CONTEXT);
        final AlertDialog alertDialog = alertDialogBuilder.create();
        alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() {
            @Override//from  w w w .j  a  v  a2s  .  c  om
            public void onClick(final DialogInterface dialog, final int which) {
                String methodName = ".showResultLogin/loginOK/onClick : ";
                LOG.d(methodName + "Entre");
                DiasporaConfig.ParamsOK = true;
                DiasporaConfig.DB.putBoolean("configOK", true);
                LOG.d(methodName + "Params to true");

                LOG.d(methodName + "main activity type is " + activity.getClass().getName());
                if (activity instanceof MainActivity_) {
                    LOG.d(methodName + "call set defaultView on MainActivity_");
                    ((MainActivity_) activity).setDefaultView();
                } else if (activity instanceof MainActivity) {
                    LOG.d(methodName + "call set defaultView on MainActivity");
                    ((MainActivity) activity).setDefaultView();
                }
                alertDialog.dismiss();
            }
        });
        alertDialog.setIcon(R.drawable.ic_launcher);
        alertDialog.setTitle("Connexion russie");
        alertDialog.setMessage("Vos paramtres sont correctes.\nBon surf sur Diaspora !");
        alertDialog.show();
        LOG.d(methodName + "Sortie");
        return;
    }
    final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(DiasporaConfig.APPLICATION_CONTEXT);
    final AlertDialog alertDialog = alertDialogBuilder.create();
    alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(final DialogInterface dialog, final int which) {
            String methodName = ".showResultLogin/loginKO/onClick : ";
            LOG.d(methodName + "Entre");
            DiasporaConfig.ParamsOK = false;
            DiasporaConfig.DB.putBoolean("configOK", false);
            LOG.d(methodName + "Params to false");
            alertDialog.dismiss();
        }
    });
    alertDialog.setIcon(R.drawable.ic_launcher);
    alertDialog.setTitle("PB Connexion");
    alertDialog.setMessage("La connexion a Diaspora a choue");
    alertDialog.show();
    LOG.d(methodName + "Sortie en erreur");
}

From source file:org.epstudios.epcoding.ScreenSlideActivity.java

protected void displayResult(String title, String message, Context context) {
    AlertDialog dialog = new AlertDialog.Builder(context).create();
    dialog.setMessage(message);//from   w w  w .  j  a  v  a 2s . c  o m
    dialog.setButton(DialogInterface.BUTTON_POSITIVE, "Exit Wizard", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            finish();
        }
    });
    dialog.setButton(DialogInterface.BUTTON_NEUTRAL, "Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            // just close dialog
        }
    });
    dialog.setTitle(title);
    dialog.show();
}

From source file:com.secbro.qark.customintent.ChooseIntentUseCaseActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // Check which request we're responding to
    if (requestCode == START_ACTIVITY_FOR_RESULT) {
        // Make sure the request was successful
        if (resultCode == RESULT_OK) {
            AlertDialog result = new AlertDialog.Builder(this).create();
            result.setTitle("Result from startActivityForResult()");
            result.setMessage(data.getDataString());
            result.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();/*from w w w  .j  a  va  2s.c o m*/
                }
            });
            result.show();
        }
    }
}

From source file:net.majorkernelpanic.spydroid.ui.UploadFragment.java

@Override
public void onItemClick(AdapterView<?> arg0, View view, int position, long id) {
    // TODO Auto-generated method stub

    final File file = (File) view.getTag();

    AlertDialog alertDialog = new AlertDialog.Builder(context).setTitle("?")
            .setMessage("?").setIcon(R.drawable.icon).create();
    alertDialog.setButton(Dialog.BUTTON_POSITIVE, "", new DialogInterface.OnClickListener() {

        @Override//from   w w w  .  j  a v a 2 s  .c  om
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub
            if (which == Dialog.BUTTON_POSITIVE) {
                UploadManager.getInstance().upload(file);
            } else {
                dialog.dismiss();
            }
        }
    });
    alertDialog.show();

}

From source file:com.danvelazco.fbwrapper.preferences.FacebookPreferences.java

/**
 * Show an alert dialog with the information about the application.
 *///from  w  w  w .j a  va  2 s .co m
private void showAboutAlert() {
    AlertDialog alertDialog = new AlertDialog.Builder(this).create();
    alertDialog.setTitle(getString(R.string.menu_about));
    alertDialog.setMessage(getString(R.string.txt_about));
    alertDialog.setIcon(R.drawable.ic_launcher);
    alertDialog.setButton(DialogInterface.BUTTON_NEUTRAL, getString(R.string.lbl_dialog_close),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    // Don't do anything, simply close the dialog
                }
            });
    alertDialog.show();
}