AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.MyAlertDialogStyle); builder.setTitle("AppCompatDialog"); builder.setMessage("Lorem ipsum dolor..."); builder.setPositiveButton("OK", null); builder.setNegativeButton("Cancel", null); builder.show();
@Override public void onClick(View v) { new AlertDialog.Builder(DisplayLeakActivity.this).setIcon( android.R.drawable.ic_dialog_alert) .setTitle(R.string.leak_canary_delete_all) .setMessage(R.string.leak_canary_delete_all_leaks_title) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { deleteAllLeaks(); } }) .setNegativeButton(android.R.string.cancel, null) .show(); } });
AlertDialog.Builder builder = new AlertDialog.Builder(SecondActivity.this, R.style.AppCompatAlertDialogStyle); builder.setTitle("SCRUM"); builder.setMessage("In the SCRUM methodology a sprint is the basic unit of development. Each sprint is preceded by a planning meeting, where the tasks for the sprint are identified and an estimated commitment for the sprint goal is made, and followed by a review or retrospective meeting where the progress is reviewed and lessons for the next sprint are identified. During each sprint, the team creates finished portions of a product....."); builder.setPositiveButton("OK", null);//second parameter used for onclicklistener builder.setNegativeButton("Cancel", null); builder.show();
public void showNoticeDialog(String alertInfo, final Thread thread) { AlertDialog.Builder builder = new AlertDialog.Builder(mContext); builder.setTitle(noticeTitle); builder.setMessage(alertInfo); builder.setPositiveButton(positiveButtonString, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); showDownloadDialog(); thread.start(); } }); builder.setNegativeButton(negativeButtonString, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); AlertDialog noticeDialog = builder.create(); // noticeDialog.setContentView(v); WindowManager.LayoutParams lp = noticeDialog.getWindow().getAttributes(); lp.height = 200; noticeDialog.getWindow().setAttributes(lp); noticeDialog.setCancelable(false); noticeDialog.show(); }
Intent intent; intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(file, "application/pdf"); try { startActivity(intent); } catch (ActivityNotFoundException e) { // No application to view, ask to download one AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("No Application Found"); builder.setMessage("Download one from Android Market?"); builder.setPositiveButton("Yes, Please", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent marketIntent = new Intent(Intent.ACTION_VIEW); marketIntent .setData(Uri .parse("market://details?id=com.adobe.reader")); startActivity(marketIntent); } }); builder.setNegativeButton("No, Thanks", null); builder.create().show(); } }
private void getCustomFood() { String title = getActivity().getResources().getString(R.string.enter_meal); final EditText input = new EditText(getActivity()); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(title) .setCancelable(true) .setView(input) .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { foodChoice = input.getText().toString(); setFoodText(); notifyDataChanged(); } }) .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { } }); AlertDialog dialog = builder.create(); // always popup the keyboard when the alert dialog shows dialog.getWindow().setSoftInputMode( WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); dialog.show(); }
.setTitle(title) .setPositiveButton(rate, handler) .setNeutralButton(skip, handler) .setNegativeButton(update, handler) .create();
@Nullable @Override public View onCreateView(final LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable final Bundle savedInstanceState) { final View view = inflater.inflate(R.layout.notes_fragment, container, false); // Find the clear button and wire the click listener to call the clear notes updatable view.findViewById(R.id.clear).setOnClickListener(v -> notesStore.clearNotes()); // Find the add button and wire the click listener to show a dialog that in turn calls the add // note from text from the notes store when adding notes view.findViewById(R.id.add).setOnClickListener(v -> { final EditText editText = new EditText(v.getContext()); editText.setId(R.id.edit); new AlertDialog.Builder(v.getContext()) .setTitle(R.string.add_note) .setView(editText) .setPositiveButton(R.string.add, (d, i) -> { notesStore.insertNoteFromText(editText.getText().toString()); }) .create().show(); }); // Setup the recycler view using the repository adapter recyclerView = (RecyclerView) view.findViewById(R.id.result); recyclerView.setAdapter(adapter); recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); final ImageView imageView = (ImageView) view.findViewById(R.id.background); updatable = () -> backgroundRepository.get().ifSucceededSendTo(imageView::setImageBitmap); return view; }
/** * Display a dialog that user has no internet connection * @param ctx1 * * Code from: http://osdir.com/ml/Android-Developers/2009-11/msg05044.html */ public static void showNoConnectionDialog(Context ctx1) { final Context ctx = ctx1; AlertDialog.Builder builder = new AlertDialog.Builder(ctx); builder.setCancelable(true); builder.setMessage(R.string.no_connection); builder.setTitle(R.string.no_connection_title); builder.setPositiveButton(R.string.settings, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { ctx.startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS)); } }); builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { return; } }); builder.setOnCancelListener(new DialogInterface.OnCancelListener() { public void onCancel(DialogInterface dialog) { return; } }); builder.show(); }
// Dialog box public void dialogBox() { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this); alertDialogBuilder.setMessage("Click on Image for tag"); alertDialogBuilder.setPositiveButton("Ok", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { } }); alertDialogBuilder.setNegativeButton("cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { } }); AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); }
@NonNull @Override public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { if (getStreams() == null) return super.onCreateDialog(savedInstanceState); View dialogView = View.inflate(getContext(), R.layout.dialog_playlist_name, null); EditText nameInput = dialogView.findViewById(R.id.playlist_name); final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getContext()) .setTitle(R.string.create_playlist) .setView(dialogView) .setCancelable(true) .setNegativeButton(R.string.cancel, null) .setPositiveButton(R.string.create, (dialogInterface, i) -> { final String name = nameInput.getText().toString(); final LocalPlaylistManager playlistManager = new LocalPlaylistManager(NewPipeDatabase.getInstance(getContext())); final Toast successToast = Toast.makeText(getActivity(), R.string.playlist_creation_success, Toast.LENGTH_SHORT); playlistManager.createPlaylist(name, getStreams()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(longs -> successToast.show()); }); return dialogBuilder.create(); } }
public void onDialog(View view) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setIcon(android.R.drawable.ic_dialog_info); builder.setTitle("Test animation"); builder.setMessage("Animator for dialog"); builder.setPositiveButton("ok", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); AlertDialog dialog = builder.create(); dialog.show(); Window window = dialog.getWindow(); assert window != null; ViewAnimator.animate(view, window.getDecorView()) .slideBottomIn() .interpolator(new DecelerateInterpolator()) .start(); }
btnblur.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { AlertDialog.Builder builder=new AlertDialog.Builder(BlurImageView.this,R.style.Theme_D1NoTitleDim); builder.setTitle("Content"); builder.setMessage("CLICK OK to Exit"); builder.setPositiveButton("ON", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { back_dim_layout.setVisibility(View.GONE); dialog.cancel(); } }); alert=builder.create(); Bitmap map=takeScreenShot(BlurImageView.this); Bitmap fast=fastblur(map, 10); final Drawable draw=new BitmapDrawable(getResources(),fast); alert.getWindow().setBackgroundDrawable(draw); alert.show(); } });
@NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(R.string.dialog_openkeychain_info_title); builder.setView(LayoutInflater.from(getActivity()).inflate( R.layout.dialog_openkeychain_info, null, false)); builder.setNegativeButton(R.string.cancel_action, new OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { dismiss(); } }); builder.setPositiveButton(R.string.dialog_openkeychain_info_install, new OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { startOpenKeychainInstallActivity(); dismiss(); } }); return builder.create(); }
LocationManager manager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); if(!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { //Ask the user to enable GPS AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Location Manager"); builder.setMessage("Would you like to enable GPS?"); builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //Launch settings, allowing user to make a change Intent i = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivity(i); } }); builder.setNegativeButton("No", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //No location service, no Activity finish(); } }); builder.create().show(); }
@Override public void onActivityResult(int requestCode, int resultCode, @NonNull Intent data) { super.onActivityResult(requestCode, resultCode, data); if (DEBUG) { Log.d(TAG, "onActivityResult() called with: requestCode = [" + requestCode + "], resultCode = [" + resultCode + "], data = [" + data + "]"); } if ((requestCode == REQUEST_IMPORT_PATH || requestCode == REQUEST_EXPORT_PATH) && resultCode == Activity.RESULT_OK && data.getData() != null) { String path = Utils.getFileForUri(data.getData()).getAbsolutePath(); if (requestCode == REQUEST_EXPORT_PATH) { SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US); exportDatabase(path + "/NewPipeData-" + sdf.format(new Date()) + ".zip"); } else { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setMessage(R.string.override_current_data) .setPositiveButton(android.R.string.ok, (DialogInterface d, int id) -> importDatabase(path)) .setNegativeButton(android.R.string.cancel, (DialogInterface d, int id) -> d.cancel()); builder.create().show(); } } }
private AlertDialog showDownloadDialog() { AlertDialog.Builder downloadDialog = new AlertDialog.Builder(activity); downloadDialog.setTitle(title); downloadDialog.setMessage(message); downloadDialog.setPositiveButton(buttonYes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { downloadDialog.setNegativeButton(buttonNo, null); downloadDialog.setCancelable(true); return downloadDialog.show();
@Override public Dialog onCreateDialog(int id) { if (id == DIALOG_NOTE) { if (mProvider != null && mProvider.note != null) { return new AlertDialog.Builder(this) .setMessage(mProvider.note) .setPositiveButton( getString(R.string.okay_action), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { finishAutoSetup(); } }) .setNegativeButton( getString(R.string.cancel_action), null) .create(); } } return null; }
android.nfc.NfcAdapter mNfcAdapter= android.nfc.NfcAdapter.getDefaultAdapter(v.getContext()); if (!mNfcAdapter.isEnabled()) { AlertDialog.Builder alertbox = new AlertDialog.Builder(v.getContext()); alertbox.setTitle("Info"); alertbox.setMessage(getString(R.string.msg_nfcon)); alertbox.setPositiveButton("Turn On", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { Intent intent = new Intent(Settings.ACTION_NFC_SETTINGS); startActivity(intent); } else { Intent intent = new Intent(Settings.ACTION_WIRELESS_SETTINGS); startActivity(intent); } } }); alertbox.setNegativeButton("Close", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); alertbox.show(); }
/** * Build the dialog from the values in config * * @param savedInstanceState old state to restore */ protected void buildAndShowDialog(@Nullable Bundle savedInstanceState) { final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this); final String title = dialogConfiguration.title(); if (title != null) { dialogBuilder.setTitle(title); } final int iconResourceId = dialogConfiguration.resIcon(); if (iconResourceId != ACRAConstants.DEFAULT_RES_VALUE) { dialogBuilder.setIcon(iconResourceId); } dialogBuilder.setView(buildCustomView(savedInstanceState)) .setPositiveButton(dialogConfiguration.positiveButtonText(), this) .setNegativeButton(dialogConfiguration.negativeButtonText(), this); mDialog = dialogBuilder.create(); mDialog.setCanceledOnTouchOutside(false); mDialog.show(); }