List of usage examples for android.app AlertDialog getButton
public Button getButton(int whichButton)
From source file:com.fitme.MainActivity.java
public void onTrainingCreationRequested(final TrainingsListAdapter tla) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.title_add_training_dialog); View addTrainDialogView = getLayoutInflater().inflate(R.layout.dialog_add_training, null); builder.setView(addTrainDialogView); builder.setPositiveButton(android.R.string.ok, null); builder.setNegativeButton(android.R.string.cancel, null); final AlertDialog trainingDialog = builder.create(); trainingDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override/*from w ww .j a v a 2s . com*/ public void onShow(DialogInterface dialog) { Button positive = trainingDialog.getButton(AlertDialog.BUTTON_POSITIVE); positive.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // handle OK EditText etName = (EditText) trainingDialog.findViewById(R.id.edittext_training_name); String trainingName = etName.getText().toString(); // Check if form filled correct // Check if training name is empty if (trainingName.isEmpty()) { Toast.makeText(MainActivity.this, getString(R.string.toast_err_training_empty), Toast.LENGTH_SHORT).show(); return; } // Check if training already exists long programId = getActiveProgramId(); TrainingDAO td = new TrainingDAO(MainActivity.this); if (td.getTrainingByName(programId, trainingName) .getId() != TrainingDAO.ID_TRAINING_NOT_FOUND) { Toast.makeText(MainActivity.this, getString(R.string.toast_err_training_exists), Toast.LENGTH_SHORT).show(); return; } // If everything is ok - then add new program Training t = new Training(); t.setName(trainingName); t.setProgramId(programId); //Insert entry to db td.createTraining(t); Toast.makeText(MainActivity.this, getText(R.string.toast_add_training_ok), Toast.LENGTH_SHORT).show(); tla.addTraining(t); trainingDialog.dismiss(); } }); Button negative = trainingDialog.getButton(AlertDialog.BUTTON_NEGATIVE); negative.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { trainingDialog.dismiss(); } }); } }); trainingDialog.show(); }
From source file:id.satusatudua.sigap.ui.fragment.TrustedsFragment.java
private void removeTrustedUser(UserTrusted userTrusted) { AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).setIcon(R.mipmap.ic_launcher) .setTitle(R.string.app_name) .setMessage("Apakah anda ingin menghapus " + userTrusted.getUser().getName() + " dari daftar kontak terpercaya anda?") .setPositiveButton("YA, Hapus Dia", (dialog, which) -> { trustedUserPresenter.removeTrustedUser(userTrusted); dialog.dismiss();/* www .j ava2 s. c om*/ }).setNegativeButton("TIDAK", (dialog, which1) -> { dialog.dismiss(); }).show(); alertDialog.getButton(DialogInterface.BUTTON_POSITIVE) .setTextColor(ContextCompat.getColor(getActivity(), R.color.colorPrimary)); alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE) .setTextColor(ContextCompat.getColor(getActivity(), R.color.primary_text)); alertDialog.show(); }
From source file:it.imwatch.nfclottery.dialogs.InsertContactDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { // Use the Builder class for convenient dialog construction final Activity activity = getActivity(); if (activity == null) { Log.e(TAG, "Not attached to Activity: cannot build dialog"); return null; }//w w w . java 2s . c o m AlertDialog.Builder builder = new AlertDialog.Builder(activity); // Get the layout inflater LayoutInflater inflater = LayoutInflater.from(activity); final View rootView = inflater.inflate(R.layout.dialog_insert, null); if (rootView == null) { Log.e(TAG, "Cannot inflate the dialog layout!"); return null; } mErrorAnimTranslateY = getResources().getDimensionPixelSize(R.dimen.error_anim_translate_y); mEmailErrorTextView = (TextView) rootView.findViewById(R.id.lbl_email_error); mNameErrorTextView = (TextView) rootView.findViewById(R.id.lbl_name_error); // Restore instance state (if any) if (savedInstanceState != null) { mNameErrorState = savedInstanceState.getInt(EXTRA_NAME_ERROR, 0); mEmailErrorState = savedInstanceState.getInt(EXTRA_EMAIL_ERROR, 0); if (mNameErrorState == 1) showNameError(); if (mEmailErrorState == 1) { showEmailError(activity.getString(R.string.error_emailinput_invalid), 1); } else if (mEmailErrorState == 2) { showEmailError(activity.getString(R.string.error_emailinput_duplicate), 2); } } mEmailEditText = (EditText) rootView.findViewById(R.id.txt_edit_email); mNameEditText = (EditText) rootView.findViewById(R.id.txt_edit_name); mOrganizationEditText = (EditText) rootView.findViewById(R.id.txt_edit_organization); mTitleEditText = (EditText) rootView.findViewById(R.id.txt_edit_title); // Add the check for a valid email address and names mEmailEditText.setOnFocusChangeListener(mFocusWatcher); mNameEditText.setOnFocusChangeListener(mFocusWatcher); // Add the check for a valid email during typing mEmailEditText.addTextChangedListener(mEmailTypingWatcher); // Inflate and set the layout for the dialog // Pass null as the parent view because its going in the dialog layout builder.setView(rootView).setPositiveButton(android.R.string.ok, null) .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { final Dialog thisDialog = InsertContactDialog.this.getDialog(); if (thisDialog != null) { thisDialog.cancel(); } else { Log.w(TAG, "Can't get the Dialog instance."); } } }); // Create the AlertDialog object and return it AlertDialog alertDialog = builder.create(); alertDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { final AlertDialog alertDialog = (AlertDialog) dialog; // Disable the positive button. It will be enabled only when there is a valid email final Button button = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE); if (button != null) { button.setEnabled(false); button.setOnClickListener(new DontAutoCloseDialogListener(alertDialog)); } else { Log.w(TAG, "Can't get the dialog positive button."); } alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); } }); return alertDialog; }
From source file:emu.project64.GalleryActivity.java
public void ShowSupportWindow() { final Context context = this; final Activity activity = this; AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(getText(R.string.GetSaveSupport_title)); builder.setMessage(getText(R.string.GetSaveSupport_message)); builder.setNeutralButton("Not now", null); builder.setNegativeButton("Support Project64", null); builder.setCancelable(false);/*from ww w . j a va 2 s. com*/ final AlertDialog dialog = builder.create(); dialog.show(); dialog.getButton(AlertDialog.BUTTON_NEUTRAL).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); StartGameMenu(false); } }); dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { setWaitScreen(true); //Purchase save support try { String payload = NativeExports.appVersion(); mIabHelper.launchPurchaseFlow(activity, SKU_SAVESUPPORT, RC_REQUEST, mPurchaseFinishedListener, payload); } catch (IabAsyncInProgressException e) { setWaitScreen(false); } dialog.dismiss(); } }); dialog.setCanceledOnTouchOutside(false); }
From source file:org.rm3l.ddwrt.tiles.admin.nvram.EditNVRAMKeyValueDialogFragment.java
@Override public void onStart() { super.onStart(); //super.onStart() is where dialog.show() is actually called on the underlying dialog, so we have to do it after this point final AlertDialog d = (AlertDialog) getDialog(); if (d != null) { ((TextView) d.findViewById(R.id.tile_admin_nvram_edit_key)).setText(this.mKey); final EditText valueEditText = (EditText) d.findViewById(R.id.tile_admin_nvram_edit_value); valueEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override/*from w ww. j a v a 2 s .c om*/ public void onFocusChange(View v, boolean hasFocus) { ((TextView) d.findViewById(R.id.tile_admin_nvram_edit_value_textview)).setTypeface(null, hasFocus ? Typeface.BOLD_ITALIC : Typeface.NORMAL); } }); valueEditText.setText(this.mValue, TextView.BufferType.EDITABLE); d.getButton(Dialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { //Validate data final EditText editText = (EditText) d.findViewById(R.id.tile_admin_nvram_edit_value); final Editable newValue = editText.getText(); if (mValue != null && StringUtils.equals(newValue.toString(), mValue.toString())) { //Crouton Crouton.makeText(getActivity(), "No change", ALERT, (ViewGroup) (d.findViewById(R.id.tile_admin_nvram_edit_notification_viewgroup))) .show(); editText.requestFocus(); //Open Keyboard final InputMethodManager imm = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); if (imm != null) { // only will trigger it if no physical keyboard is open imm.showSoftInput(editText, 0); } return; } final CharSequence variableKey = ((TextView) d.findViewById(R.id.tile_admin_nvram_edit_key)) .getText(); final Bundle token = new Bundle(); token.putInt(POSITION, mPosition); token.putCharSequence(VALUE, newValue); token.putCharSequence(KEY, variableKey); //nvram set data changed new UndoBarController.UndoBar(getSherlockActivity()) .message(String.format("Variable '%s' will be updated", variableKey)) .listener(nvramDataRecyclerViewAdapter).token(token).show(); d.cancel(); } }); } }
From source file:com.cuddlesoft.nori.fragment.AddTagFilterDialogFragment.java
@SuppressLint("InflateParams") @Override//from w ww . j a va 2 s . c om public Dialog onCreateDialog(Bundle savedInstanceState) { // Inflate the Dialog view XML. final LayoutInflater inflater = LayoutInflater.from(getActivity()); final View view = inflater.inflate(R.layout.dialog_add_tag_filter, null); tagEditText = (EditText) view.findViewById(R.id.editText); // Restore preserved text from savedInstanceState, if possible. if (savedInstanceState != null && savedInstanceState.containsKey(BUNDLE_ID_TAG_FILTER)) { tagEditText.setText(savedInstanceState.getString(BUNDLE_ID_TAG_FILTER)); } // Create the AlertDialog object. final AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).setView(view) .setPositiveButton(R.string.action_add, null) .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { // Dismiss dialog. dismiss(); } }).create(); // onShowListener is used here as a hack to override Android DialogInterface's default onClickInterface // that doesn't provide a way to prevent the dialog from getting dismissed when a button is clicked. alertDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialogInterface) { alertDialog.getButton(AlertDialog.BUTTON_POSITIVE) .setOnClickListener(AddTagFilterDialogFragment.this); } }); return alertDialog; }
From source file:net.bytten.comicviewer.ComicViewerActivity.java
@Override protected void onPrepareDialog(int id, Dialog dialog) { // Determine the type of dialog based on the integer passed. These are defined in constants // at the top of the class. switch (id) { case DIALOG_SHOW_HOVER_TEXT: //Get an alertdialog so we can edit it. AlertDialog adh = (AlertDialog) dialog; adh.setMessage(comicInfo.getAlt()); adh.getButton(AlertDialog.BUTTON_POSITIVE) .setVisibility(comicInfo.getLink() != null ? Button.VISIBLE : Button.GONE); break;// w w w . j a v a2 s . c om case DIALOG_FAILED: //Get the alertdialog for the failedDialog AlertDialog adf = (AlertDialog) dialog; adf.setMessage(errors); //Set failedDialog to our dialog so we can dismiss //it manually failedDialog = adf; break; case DIALOG_SEARCH_BY_TITLE: // Clear the text box AlertDialog ads = (AlertDialog) dialog; ((EditText) ads.findViewById(R.id.search_dlg_edit_box)).setText(""); break; default: break; } super.onPrepareDialog(id, dialog); }
From source file:io.github.tjg1.nori.fragment.AddTagFilterDialogFragment.java
@NonNull @SuppressLint("InflateParams") @Override/* ww w . j av a2 s . com*/ public Dialog onCreateDialog(Bundle savedInstanceState) { // Inflate the Dialog view XML. final LayoutInflater inflater = LayoutInflater.from(getContext()); final View view = inflater.inflate(R.layout.dialog_add_tag_filter, null); tagEditText = (EditText) view.findViewById(R.id.editText); // Restore preserved text from savedInstanceState, if possible. if (savedInstanceState != null && savedInstanceState.containsKey(BUNDLE_ID_TAG_FILTER)) { tagEditText.setText(savedInstanceState.getString(BUNDLE_ID_TAG_FILTER)); } // Create the AlertDialog object. final AlertDialog alertDialog = new AlertDialog.Builder(getContext()).setView(view) .setPositiveButton(R.string.action_add, null) .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { // Dismiss dialog. dismiss(); } }).create(); // onShowListener is used here as a hack to override Android DialogInterface's default onClickInterface // that doesn't provide a way to prevent the dialog from getting dismissed when a button is clicked. alertDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialogInterface) { alertDialog.getButton(AlertDialog.BUTTON_POSITIVE) .setOnClickListener(AddTagFilterDialogFragment.this); } }); return alertDialog; }
From source file:it.polimi.spf.app.fragments.contacts.PeopleFragment.java
private void onRequestReview(final PersonInfo entry) { final ContactConfirmDialogView dialogView = new ContactConfirmDialogView(getActivity(), entry); final AlertDialog dialog = new AlertDialog.Builder(getActivity()).setTitle("Confirm contact request") .setView(dialogView).setPositiveButton("Accept", null) .setNeutralButton("Cancel", new DialogInterface.OnClickListener() { @Override/*from www .j a va 2 s. c o m*/ public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }).setNegativeButton("Refuse", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); mPersonRegistry.deleteRequest(entry); onRefresh(); } }).show(); dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { mPersonRegistry.confirmRequest(entry, dialogView.getPassphrase(), dialogView.getSelectedCircles()); } catch (WrongPassphraseException e) { Toast.makeText(getActivity(), "Wrong passphrase", Toast.LENGTH_SHORT).show(); return; } dialog.dismiss(); onRefresh(); } }); }
From source file:de.tum.frm2.nicos_android.gui.MainActivity.java
private void exec_command(final String command) { if (!(_current_status == NicosStatus.STATUS_IDLE || _current_status == NicosStatus.STATUS_IDLEEXC)) { // Server is not idle. runOnUiThread(new Runnable() { @Override//from w w w . ja v a 2s . c om public void run() { DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { switch (which) { case DialogInterface.BUTTON_NEUTRAL: new Thread(new Runnable() { @Override public void run() { NicosClient.getClient().tell("exec", command); } }).start(); break; case DialogInterface.BUTTON_NEGATIVE: return; case DialogInterface.BUTTON_POSITIVE: new Thread(new Runnable() { @Override public void run() { NicosClient.getClient().run(command); } }).start(); break; } } }; AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); builder.setMessage("A script is currently running. What do you want to do?"); builder.setNeutralButton("Execute now!", dialogClickListener); builder.setNegativeButton("Cancel", dialogClickListener); builder.setPositiveButton("Queue script", dialogClickListener); int version = Build.VERSION.SDK_INT; int color; if (version >= 23) { color = ContextCompat.getColor(MainActivity.this, R.color.colorPrimary); } else { // It's only deprecated since API level 23. //noinspection deprecation color = getResources().getColor(R.color.colorPrimary); } AlertDialog dlg = builder.create(); dlg.show(); dlg.getButton(AlertDialog.BUTTON_NEUTRAL).setTextColor(color); dlg.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(Color.RED); dlg.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(color); } }); } else { new Thread(new Runnable() { @Override public void run() { NicosClient.getClient().run(command); } }).start(); } }