Java Code Examples for android.content.DialogInterface#OnClickListener
The following examples show how to use
android.content.DialogInterface#OnClickListener .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseActivity.java From OpenHub with GNU General Public License v3.0 | 6 votes |
@Override public void showConfirmDialog(String msn, String title, String confirmText , DialogInterface.OnClickListener confirmListener) { new AlertDialog.Builder(getActivity()) .setCancelable(true) .setTitle(title) .setMessage(msn) .setCancelable(true) .setPositiveButton(confirmText, confirmListener) .setNegativeButton("取消", new DialogInterface.OnClickListener() { @Override public void onClick(@NonNull DialogInterface dialog, int which) { dialog.cancel(); } }) .show(); }
Example 2
Source File: Main.java From currency with GNU General Public License v3.0 | 6 votes |
private void updateDialog(int title, String value, int hint, DialogInterface.OnClickListener listener) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(title); // Add the buttons builder.setPositiveButton(R.string.ok, listener); builder.setNegativeButton(R.string.cancel, listener); // Create edit text Context context = builder.getContext(); EditText text = new EditText(context); text.setId(R.id.value); text.setText(value); text.setHint(hint); text.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL); // Create the AlertDialog AlertDialog dialog = builder.create(); dialog.setView(text, 40, 0, 40, 0); dialog.show(); }
Example 3
Source File: AlertDialogBuilder.java From redalert-android with Apache License 2.0 | 6 votes |
public static final void showGenericDialog(String title, String message, Context context, DialogInterface.OnClickListener clickListener) { // Use builder to create dialog AlertDialog.Builder builder = new AlertDialog.Builder(context); // Use builder to create dialog builder.setTitle(title).setMessage(message).setCancelable(false).setPositiveButton(R.string.okay, clickListener); // Prevent cancellation builder.setCancelable(false); try { // Build it AlertDialog dialog = builder.create(); // Show it dialog.show(); // Support for RTL languages RTLSupport.mirrorDialog(dialog, context); } catch (Exception exc) { // Show toast instead Toast.makeText(context, title + " - " + message, Toast.LENGTH_LONG).show(); } }
Example 4
Source File: BiometricPrompt.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * Required: Set the text for the negative button. This would typically be used as a * "Cancel" button, but may be also used to show an alternative method for authentication, * such as screen that asks for a backup password. * @param text * @return */ public Builder setNegativeButton(@NonNull CharSequence text, @NonNull @CallbackExecutor Executor executor, @NonNull DialogInterface.OnClickListener listener) { if (TextUtils.isEmpty(text)) { throw new IllegalArgumentException("Text must be set and non-empty"); } if (executor == null) { throw new IllegalArgumentException("Executor must not be null"); } if (listener == null) { throw new IllegalArgumentException("Listener must not be null"); } mBundle.putCharSequence(KEY_NEGATIVE_TEXT, text); mNegativeButtonInfo = new ButtonInfo(executor, listener); return this; }
Example 5
Source File: FakeSignatureGlobalUI.java From haystack with GNU General Public License v3.0 | 5 votes |
static AlertDialog createWarningDialog(Activity activity, DialogInterface.OnClickListener buttonListener) { return new AlertDialog.Builder(activity) .setTitle(FakeSignatureGlobalUI.WARNING_TITLE) .setMessage(FakeSignatureGlobalUI.WARNING_MESSAGE) //.setIconAttribute(android.R.attr.alertDialogIcon) .setPositiveButton(android.R.string.yes, buttonListener) .setNegativeButton(android.R.string.no, buttonListener) .create(); }
Example 6
Source File: ChooserDialog.java From android-file-chooser with Apache License 2.0 | 5 votes |
public ChooserDialog withNegativeButton(@Nullable String cancelTitle, final DialogInterface.OnClickListener listener) { this._negative = cancelTitle; if (cancelTitle != null) this._negativeRes = -1; this._negativeListener = listener; return this; }
Example 7
Source File: MqttSettingsCodeReaderFragment.java From Bluefruit_LE_Connect_Android_V2 with MIT License | 5 votes |
@Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); if (requestCode != RC_HANDLE_CAMERA_PERM) { Log.d(TAG, "Got unexpected permission result: " + requestCode); super.onRequestPermissionsResult(requestCode, permissions, grantResults); return; } if (grantResults.length != 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { Log.d(TAG, "Camera permission granted - initialize the camera source"); // we have permission, so create the camerasource createCameraSource(kAutoFocus, kUseFlash); return; } Log.e(TAG, "Permission not granted: results len = " + grantResults.length + " Result code = " + (grantResults.length > 0 ? grantResults[0] : "(empty)")); DialogInterface.OnClickListener listener = (dialog, id) -> { FragmentActivity activity = getActivity(); if (activity != null) { FragmentManager fragmentManager = activity.getSupportFragmentManager(); fragmentManager.popBackStack(); } }; AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); builder.setMessage(R.string.mqttcodereader_nocamerapermission) .setPositiveButton(android.R.string.ok, listener) .show(); }
Example 8
Source File: AlertDialogManager.java From QuickDevFramework with Apache License 2.0 | 5 votes |
/** * show alert dialog with simple message, * click event of positive button and negative button are configurable * */ public static void showAlertDialog(String message, DialogInterface.OnClickListener positiveListener, DialogInterface.OnClickListener negativeListener) { createAlertDialogBuilder() .setMessage(message) .setPositiveButton(positiveListener) .setNegativeButton(negativeListener) .show(); }
Example 9
Source File: MeetingDetails.java From UltimateAndroid with Apache License 2.0 | 5 votes |
protected DialogInterface.OnClickListener deleteMeetingConfirmationListener() { return new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { meeting.delete(MeetingDetails.this); finish(); } }; }
Example 10
Source File: MusicListActivity.java From PlayWidget with MIT License | 5 votes |
/** * Check if we have necessary permissions. */ @TargetApi(Build.VERSION_CODES.JELLY_BEAN) private void checkReadStoragePermission() { if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_EXTERNAL_STORAGE)) { DialogInterface.OnClickListener onClickListener = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (which == DialogInterface.BUTTON_POSITIVE) { ActivityCompat.requestPermissions(MusicListActivity.this, new String[] { Manifest.permission.READ_EXTERNAL_STORAGE }, EXT_STORAGE_PERMISSION_REQ_CODE); } else if (which == DialogInterface.BUTTON_NEGATIVE) { onPermissionsNotGranted(); } dialog.dismiss(); } }; new AlertDialog.Builder(this) .setTitle(R.string.permissions_title) .setMessage(R.string.read_ext_permissions_message) .setPositiveButton(R.string.btn_continue, onClickListener) .setNegativeButton(R.string.btn_cancel, onClickListener) .setCancelable(false) .show(); return; } ActivityCompat.requestPermissions(MusicListActivity.this, new String[] { Manifest.permission.READ_EXTERNAL_STORAGE }, EXT_STORAGE_PERMISSION_REQ_CODE); return; } loadMusic(); }
Example 11
Source File: AlertController.java From PreferenceFragment with Apache License 2.0 | 5 votes |
/** * Sets a click listener or a message to be sent when the button is clicked. * You only need to pass one of {@code listener} or {@code msg}. * * @param whichButton Which button, can be one of * {@link DialogInterface#BUTTON_POSITIVE}, * {@link DialogInterface#BUTTON_NEGATIVE}, or * {@link DialogInterface#BUTTON_NEUTRAL} * @param text The text to display in positive button. * @param listener The {@link DialogInterface.OnClickListener} to use. * @param msg The {@link Message} to be sent when clicked. */ public void setButton(int whichButton, CharSequence text, DialogInterface.OnClickListener listener, Message msg) { if (msg == null && listener != null) { msg = mHandler.obtainMessage(whichButton, listener); } switch (whichButton) { case DialogInterface.BUTTON_POSITIVE: mButtonPositiveText = text; mButtonPositiveMessage = msg; break; case DialogInterface.BUTTON_NEGATIVE: mButtonNegativeText = text; mButtonNegativeMessage = msg; break; case DialogInterface.BUTTON_NEUTRAL: mButtonNeutralText = text; mButtonNeutralMessage = msg; break; default: throw new IllegalArgumentException("Button does not exist"); } }
Example 12
Source File: RadioDialog.java From Lanmitm with GNU General Public License v2.0 | 5 votes |
public Builder setRadio4(int radioText, boolean checked, DialogInterface.OnClickListener listener) { this.radioText3 = (String) context.getText(radioText); this.radioClickListener3 = listener; this.radioCheck3 = checked; return this; }
Example 13
Source File: BaseRecyclerAdapter.java From BmapLite with GNU General Public License v3.0 | 5 votes |
protected void showAlertDialog(String title, String msg, DialogInterface.OnClickListener okListener, DialogInterface.OnClickListener cancelListener) { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(title); builder.setMessage(msg); builder.setCancelable(false); if (okListener != null) { builder.setPositiveButton("确定", okListener); } if (cancelListener != null) { builder.setNegativeButton("取消", cancelListener); } builder.create().show(); }
Example 14
Source File: ViewUtil.java From VBrowser-Android with GNU General Public License v2.0 | 5 votes |
/** * 弹出一个带确认和取消的dialog * @param context * @param title * @param msg * @param okbutton * @param ok 点击确定事件 * @param nobutton * @param no 点击取消事件 * @return */ public static AlertDialog openConfirmDialog(Context context, String title, String msg, String okbutton, DialogInterface.OnClickListener ok, String nobutton, DialogInterface.OnClickListener no) { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(title); builder.setMessage("\n" + msg + "\n"); builder.setNegativeButton(okbutton, ok); builder.setNeutralButton(nobutton, no); AlertDialog loadWaitDialog = builder.create(); loadWaitDialog.setCanceledOnTouchOutside(false); loadWaitDialog.show(); return loadWaitDialog; }
Example 15
Source File: FunCustomDialog.java From RePlugin-GameSdk with Apache License 2.0 | 5 votes |
/** * Set the positive button resource and it's listener * * @param positiveButtonText * @return */ public Builder setPositiveButton(int positiveButtonText, DialogInterface.OnClickListener listener) { this.positiveButtonText = (String) context .getText(positiveButtonText); this.positiveButtonClickListener = listener; return this; }
Example 16
Source File: AlertDialogFragment.java From Android-Next with Apache License 2.0 | 4 votes |
public Builder setItems(CharSequence[] items, final DialogInterface.OnClickListener listener) { mParams.mItems = items; mParams.mOnClickListener = listener; return this; }
Example 17
Source File: BaseFragment.java From social-app-android with Apache License 2.0 | 4 votes |
@Override public void showWarningDialog(String message, DialogInterface.OnClickListener listener) { ((BaseActivity) getActivity()).showWarningDialog(message, listener); }
Example 18
Source File: Dialogs.java From Aegis with GNU General Public License v3.0 | 4 votes |
public static void showErrorDialog(Context context, @StringRes int message, Exception e, DialogInterface.OnClickListener listener) { showErrorDialog(context, message, e.toString(), listener); }
Example 19
Source File: AlertDialogFragment.java From Android-Next with Apache License 2.0 | 4 votes |
public Builder setAdapter(final ListAdapter adapter, final DialogInterface.OnClickListener listener) { mParams.mAdapter = adapter; mParams.mOnClickListener = listener; return this; }
Example 20
Source File: AbstractListDialogBuilder.java From AndroidMaterialDialog with Apache License 2.0 | 3 votes |
/** * Sets the selectable items, which should be shown by the dialog, which is created by the * builder. Only one of the items can be selected at once. * <p> * Note, that the attached listener is not stored using a dialog's * <code>onSaveInstanceState</code>-method, because it is not serializable. Therefore this * method must be called again after configuration changes, e.g when the orientation of the * device has changed, in order to re-register the listener. * * @param items * The items, which should be set, as an array of the type {@link CharSequence}. The * items may not be null * @param iconResourceIds * An array, which contains the resource ids of the items' icons, as an {@link Integer} * array or null, if no icons should be displayed * @param checkedItem * The index of the item, which should be selected by default, as an {@link Integer} * value or -1, if no item should be selected by default * @param listener * The listener, which should be notified, when an item is clicked, as an instance of * the type {@link DialogInterface.OnClickListener} or null, if no listener should be * notified * @return The builder, the method has been called upon, as an instance of the generic type * BuilderType */ public final BuilderType setSingleChoiceItems(@NonNull final CharSequence[] items, @Nullable final int[] iconResourceIds, final int checkedItem, @Nullable final DialogInterface.OnClickListener listener) { getProduct().setSingleChoiceItems(items, iconResourceIds, checkedItem, listener); return self(); }