Java Code Examples for android.support.v7.app.AlertDialog#show()
The following examples show how to use
android.support.v7.app.AlertDialog#show() .
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: TrackerActivity.java From DanDanPlayForAndroid with MIT License | 6 votes |
@OnClick(R.id.add_tracker_bt) public void onViewClicked() { View dialogView = getLayoutInflater().inflate(R.layout.dialog_tracker_add, null); AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog addTrackerDialog = builder.setTitle("添加Tracker") .setView(dialogView) .setPositiveButton("确定", null) .setNegativeButton("取消", null) .create(); addTrackerDialog.show(); addTrackerDialog.getButton(DialogInterface.BUTTON_POSITIVE) .setOnClickListener(v -> { EditText trackerEt = dialogView.findViewById(R.id.tracker_et); String trackerText = trackerEt.getText().toString().trim(); if (addTracker(trackerText)) addTrackerDialog.dismiss(); }); }
Example 2
Source File: AddCustomFermentableActivity.java From biermacht with Apache License 2.0 | 6 votes |
@Override public void onMissedClick(View v) { super.onMissedClick(v); Log.d("AddCustomFerm", "Checking views for: " + v); AlertDialog alert; if (v.equals(descriptionView)) { Log.d("AddCustomFerm", "Displaying descriptionView edit alert"); alert = alertBuilder.editTextMultilineStringAlert(descriptionViewText, descriptionViewTitle).create(); } else { Log.d("AddCustomFerm", "View not found: " + v); return; } // Force keyboard open and show popup alert.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); alert.show(); }
Example 3
Source File: AboutActivity.java From Memory-capsule with Apache License 2.0 | 6 votes |
private void initEditpassworddialog(){//实例化一个重新编辑密码的dialog AlertDialog.Builder builder=new AlertDialog.Builder(this); LayoutInflater layoutInflater=LayoutInflater.from(this); View centerview=layoutInflater.inflate(R.layout.activity_set_editpassworddialog,null); final MaterialEditText materialEditText_password=(MaterialEditText)centerview.findViewById(R.id.set_dialog_password_edit_password); final TextView texttitle=(TextView)centerview.findViewById(R.id.title_text_password); Button button_ok=(Button)centerview.findViewById(R.id.set_dialog_password_ok_password); final AlertDialog alertDialog_editpassword=builder.setView(centerview).create(); texttitle.setText("请输入旧密码"); button_ok.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (prestenerImp_about.iscurrentthepasswordfromSeting(materialEditText_password.getText().toString())){ initEditnewpasssworddialog(); alertDialog_editpassword.dismiss(); }else { Toast.makeText(AboutActivity.this, "输入密码有误", Toast.LENGTH_SHORT).show(); } } }); alertDialog_editpassword.show(); }
Example 4
Source File: DialogActivity.java From android-md-core with Apache License 2.0 | 6 votes |
@OnClick(R.id.btn_dialog_2) protected void onBtnDialog2Click() { AlertDialog dialog = new AlertDialog.Builder(DialogActivity.this) .setTitle(getString(R.string.text_custom_dialog)) .setView(R.layout.custom_dialog) .setPositiveButton(R.string.text_ok, null) .setNegativeButton(R.string.text_cancel, null) .create(); dialog.setOnShowListener(d -> { AlertDialog alertDialog = (AlertDialog) d; Button positiveButton = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE); CheckBox checkBox = (CheckBox) alertDialog.findViewById(R.id.checkbox); checkBox.setOnCheckedChangeListener((buttonView, isChecked) -> positiveButton.setEnabled(isChecked)); positiveButton.setEnabled(checkBox.isChecked()); }); dialog.show(); }
Example 5
Source File: CopySeedDialog.java From android-wallet-app with GNU General Public License v3.0 | 5 votes |
@NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { Bundle bundle = getArguments(); generatedSeed = bundle.getString("generatedSeed"); final AlertDialog alertDialog = new AlertDialog.Builder(getActivity()) .setTitle(R.string.copy_seed) .setMessage(R.string.messages_copy_seed) .setCancelable(false) .setPositiveButton(R.string.buttons_ok, null) .setNegativeButton(R.string.buttons_cancel, null) .create(); alertDialog.setOnShowListener(dialog -> { Button button = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE); button.setOnClickListener(view -> { ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText(getActivity().getString(R.string.seed), generatedSeed); clipboard.setPrimaryClip(clip); dialog.dismiss(); }); }); alertDialog.show(); return alertDialog; }
Example 6
Source File: MainActivity.java From journaldev with MIT License | 5 votes |
public void withItems(View view) { final String[] items = {"Apple", "Banana", "Orange", "Grapes"}; AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("List of Items") .setItems(items, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Toast.makeText(getApplicationContext(), items[which] + " is clicked", Toast.LENGTH_SHORT).show(); } }); builder.setPositiveButton("OK", null); builder.setNegativeButton("CANCEL", null); builder.setNeutralButton("NEUTRAL", null); builder.setPositiveButtonIcon(getResources().getDrawable(android.R.drawable.ic_menu_call, getTheme())); builder.setIcon(getResources().getDrawable(R.drawable.jd, getTheme())); AlertDialog alertDialog = builder.create(); alertDialog.show(); Button button = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE); button.setBackgroundColor(Color.BLACK); button.setPadding(0, 0, 20, 0); button.setTextColor(Color.WHITE); }
Example 7
Source File: BaseActivity.java From BlogDemo with Apache License 2.0 | 5 votes |
/** * 提示对话框,带有“确定”和“取消”两个按钮 * * @param title 标题 * @param message 提示内容 * @param listener “确定”按钮的点击监听器 */ protected void showAlertDialog(String title, String message, DialogInterface.OnClickListener listener) { AlertDialog dialog = new AlertDialog.Builder(this).setTitle(title).setMessage(message) .setPositiveButton(R.string.btn_confirm, listener) .setNegativeButton(R.string.btn_cancel, null).create(); dialog.setCanceledOnTouchOutside(false); dialog.show(); }
Example 8
Source File: PostFragment.java From Nimingban with Apache License 2.0 | 5 votes |
private void handleReferenceSpan(ReferenceSpan referenceSpan) { ReferenceDialogHelper helper = new ReferenceDialogHelper(referenceSpan.getSite(), referenceSpan.getId()); AlertDialog dialog = new AlertDialog.Builder(getContext()).setView(helper.getView()) .setOnDismissListener(helper).create(); helper.setDialog(dialog); dialog.show(); helper.request(); }
Example 9
Source File: SendFeedBack.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
private void askType() { final CharSequence[] items = {"Bug Report", "Compliment", "Question", "Other"}; AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Type of feedback?"); builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { type_of_message = items[item].toString(); dialog.dismiss(); } }); final AlertDialog typeDialog = builder.create(); typeDialog.show(); }
Example 10
Source File: TeamMineActivity.java From Android-Application-ZJB with Apache License 2.0 | 5 votes |
/** * 没有可邀请的成员 的提示 */ private void noInviterShow() { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setCancelable(false); builder.setView(R.layout.dlg_team_noinviter); AlertDialog dialog = builder.create(); dialog.show(); dialog.findViewById(R.id.dlg_noinviter_bt).setOnClickListener(v -> dialog.dismiss()); }
Example 11
Source File: ArticlesFragment.java From WanAndroid with Apache License 2.0 | 5 votes |
@Override public void showAutoLoginFail() { final AlertDialog alertDialog = new AlertDialog.Builder(getContext()).create(); alertDialog.setTitle(R.string.warning_title); alertDialog.setMessage(getString(R.string.tip)); alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.sure), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { MainActivity main = (MainActivity) getActivity(); main.navigateToLogin(); alertDialog.dismiss(); } }); alertDialog.show(); }
Example 12
Source File: PostViewActivity.java From quill with MIT License | 5 votes |
private void onDeleteClicked() { // confirm deletion final AlertDialog alertDialog = new AlertDialog.Builder(this) .setTitle(R.string.alert_delete_draft_title) .setMessage(R.string.alert_delete_draft_msg) .setPositiveButton(R.string.alert_delete_yes, (dialog, which) -> { getBus().post(new DeletePostEvent(mPost)); dialog.dismiss(); }) .setNegativeButton(R.string.alert_delete_no, (dialog, which) -> { dialog.dismiss(); }) .create(); alertDialog.show(); }
Example 13
Source File: BaseView.java From mvp-sample with Apache License 2.0 | 5 votes |
public void showMessageDialog(CharSequence title, CharSequence message) { AlertDialog alertDialog = new AlertDialog.Builder(getContext()) .setTitle(title) .setMessage(message) .setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }) .create(); alertDialog.show(); }
Example 14
Source File: HomeFragment.java From fitnotifications with Apache License 2.0 | 4 votes |
private void sendDebugLogEmail(final StringBuilder body) { final LinearLayout layout = new LinearLayout(getContext()); layout.setOrientation(LinearLayout.VERTICAL); layout.setPadding(32,16,32,16); final TextView title = new TextView(getContext()); title.setText("Explain the problem below:"); title.setTextSize(18); final EditText input = new EditText(getContext()); layout.addView(title); layout.addView(input); final AlertDialog dialog = new AlertDialog.Builder(getContext()) .setTitle("Send Logs: Step 1") .setView(layout) .setPositiveButton(android.R.string.ok, null) .setNegativeButton(android.R.string.cancel, null) .create(); dialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialogInterface) { Button button = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { String issue = input.getText().toString(); issue = issue.trim(); if (issue.isEmpty()) { Toast.makeText(getContext(), "You must describe the problem you are facing to proceed!", Toast.LENGTH_SHORT).show(); } else { body.insert(0, "\n\n------\n\n"); body.insert(0, issue); DebugLog log = DebugLog.get(getActivity()); startActivity(log.emailLogIntent(getContext(), body.toString())); mEnableLogs.setChecked(false); dialog.dismiss(); } } }); } }); dialog.show(); }
Example 15
Source File: EditorActivity.java From MarkdownEditors with Apache License 2.0 | 4 votes |
/** * 插入表格 */ private void insertTable() { View rootView = LayoutInflater.from(this).inflate(R.layout.view_common_input_table_view, null); AlertDialog dialog = new AlertDialog.Builder(this) .setTitle("插入表格") .setView(rootView) .show(); TextInputLayout rowNumberHint = (TextInputLayout) rootView.findViewById(R.id.rowNumberHint); TextInputLayout columnNumberHint = (TextInputLayout) rootView.findViewById(R.id.columnNumberHint); EditText rowNumber = (EditText) rootView.findViewById(R.id.rowNumber); EditText columnNumber = (EditText) rootView.findViewById(R.id.columnNumber); rootView.findViewById(R.id.sure).setOnClickListener(v -> { String rowNumberStr = rowNumber.getText().toString().trim(); String columnNumberStr = columnNumber.getText().toString().trim(); if (Check.isEmpty(rowNumberStr)) { rowNumberHint.setError("不能为空"); return; } if (Check.isEmpty(columnNumberStr)) { columnNumberHint.setError("不能为空"); return; } if (rowNumberHint.isErrorEnabled()) rowNumberHint.setErrorEnabled(false); if (columnNumberHint.isErrorEnabled()) columnNumberHint.setErrorEnabled(false); mEditorFragment.getPerformEditable().perform(R.id.id_shortcut_grid, Integer.parseInt(rowNumberStr), Integer.parseInt(columnNumberStr)); dialog.dismiss(); }); rootView.findViewById(R.id.cancel).setOnClickListener(v -> { dialog.dismiss(); }); dialog.show(); }
Example 16
Source File: PlayActivity.java From AudioAnchor with GNU General Public License v3.0 | 4 votes |
void showGoToDialog() { AlertDialog.Builder builder = new AlertDialog.Builder(this); final View dialogView = this.getLayoutInflater().inflate(R.layout.dialog_goto, null); builder.setView(dialogView); final EditText gotoHours = dialogView.findViewById(R.id.goto_hours); final EditText gotoMinutes = dialogView.findViewById(R.id.goto_minutes); final EditText gotoSeconds = dialogView.findViewById(R.id.goto_seconds); int currPos = getAudioCompletedTime(); String[] currPosArr = Utils.formatTime(currPos, 3600000).split(":"); gotoHours.setText(currPosArr[0]); gotoMinutes.setText(currPosArr[1]); gotoSeconds.setText(currPosArr[2]); builder.setTitle(R.string.go_to); builder.setMessage(R.string.dialog_msg_goto); // User clicked the OK button so set the sleep timer builder.setPositiveButton(R.string.dialog_msg_ok, (dialog, id) -> { String hours = gotoHours.getText().toString(); String minutes = gotoMinutes.getText().toString(); String seconds = gotoSeconds.getText().toString(); String timeString = hours + ":" + minutes + ":" + seconds; try { long millis = Utils.getMillisFromString(timeString); updateAudioCompletedTime((int) millis); } catch (NumberFormatException e) { Toast.makeText(getApplicationContext(), R.string.time_format_error, Toast.LENGTH_SHORT).show(); } }); builder.setNegativeButton(R.string.dialog_msg_cancel, (dialog, id) -> { // User clicked the "Cancel" button, so dismiss the dialog if (dialog != null) { dialog.dismiss(); } }); // Create and show the AlertDialog AlertDialog alertDialog = builder.create(); alertDialog.show(); }
Example 17
Source File: FolderManagerFragment.java From MarkdownEditors with Apache License 2.0 | 4 votes |
/** * Re name. * 重命名文件、文件夹 */ private void rename() { FileBean selectBean = mPresenter.getSelectBean(); if (selectBean == null) { return; } //显示重命名对话框 View rootView = LayoutInflater.from(mContext).inflate(R.layout.view_common_input_view, null); AlertDialog dialog = new AlertDialog.Builder(mContext) .setTitle("重命名") .setView(rootView) .show(); TextInputLayout textInputLayout = (TextInputLayout) rootView.findViewById(R.id.inputHint); EditText text = (EditText) rootView.findViewById(R.id.text); text.setText(selectBean.name); text.setSelection(0, selectBean.isDirectory ? selectBean.name.length() : selectBean.name.lastIndexOf(".")); textInputLayout.setHint("请输入" + (selectBean.isDirectory ? "文件夹名" : "文件名")); rootView.findViewById(R.id.sure).setOnClickListener(v -> { String result = text.getText().toString().trim(); if (!selectBean.isDirectory && !result.endsWith(".md") && !result.endsWith(".markdown") && !result.endsWith(".markd")) { textInputLayout.setError("文件后缀名必须为:md|markdown|markd"); return; } if (Check.isEmpty(result)) { textInputLayout.setError("不能为空"); return; } if (!selectBean.isDirectory && mPresenter.fileIsExists(result)) { textInputLayout.setError("文件已经存在"); return; } if (selectBean.isDirectory && mPresenter.createFoloderIsExists(result)) { textInputLayout.setError("文件夹已经存在"); return; } if (!mPresenter.rename(selectBean, result)) { textInputLayout.setError("重命名失败了"); return; } textInputLayout.setErrorEnabled(false); if (mActionMode != null) { mActionMode.finish(); } dialog.dismiss(); }); rootView.findViewById(R.id.cancel).setOnClickListener(v -> { dialog.dismiss(); }); dialog.show(); }
Example 18
Source File: MainActivity.java From blade-player with GNU General Public License v3.0 | 4 votes |
private void checkPermission() { if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.M) { if(checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)!= PackageManager.PERMISSION_GRANTED) { if(shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { // Show an alert dialog AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); builder.setMessage(getString(R.string.please_grant_permission_msg)); builder.setTitle(getString(R.string.please_grant_permission_title)); builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, EXT_PERM_REQUEST_CODE); } }); AlertDialog dialog = builder.create(); dialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface arg0) { dialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(Color.BLACK); } }); dialog.show(); } else { // Request permission ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, EXT_PERM_REQUEST_CODE); } } else startLibService(); } else startLibService(); }
Example 19
Source File: EditorActivity.java From MarkdownEditors with Apache License 2.0 | 4 votes |
/** * 插入链接 */ private void insertLink() { View rootView = LayoutInflater.from(this).inflate(R.layout.view_common_input_link_view, null); AlertDialog dialog = new AlertDialog.Builder(this, R.style.DialogTheme) .setTitle("插入链接") .setView(rootView) .show(); TextInputLayout titleHint = (TextInputLayout) rootView.findViewById(R.id.inputNameHint); TextInputLayout linkHint = (TextInputLayout) rootView.findViewById(R.id.inputHint); EditText title = (EditText) rootView.findViewById(R.id.name); EditText link = (EditText) rootView.findViewById(R.id.text); rootView.findViewById(R.id.sure).setOnClickListener(v -> { String titleStr = title.getText().toString().trim(); String linkStr = link.getText().toString().trim(); if (Check.isEmpty(titleStr)) { titleHint.setError("不能为空"); return; } if (Check.isEmpty(linkStr)) { linkHint.setError("不能为空"); return; } if (titleHint.isErrorEnabled()) titleHint.setErrorEnabled(false); if (linkHint.isErrorEnabled()) linkHint.setErrorEnabled(false); mEditorFragment.getPerformEditable().perform(R.id.id_shortcut_insert_link, titleStr, linkStr); dialog.dismiss(); }); rootView.findViewById(R.id.cancel).setOnClickListener(v -> { dialog.dismiss(); }); dialog.show(); }
Example 20
Source File: TemplateEditor.java From BuildmLearn-Toolkit-Android with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * {@inheritDoc} */ @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); switch (id) { case R.id.action_delete: final AlertDialog dialog = new AlertDialog.Builder(this) .setTitle(R.string.dialog_delete_title) .setMessage(R.string.dialog_delete_msg) .setPositiveButton(R.string.dialog_yes, null) .setNegativeButton(R.string.dialog_no, null) .create(); dialog.show(); dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); selectedTemplate.deleteItem(TemplateEditor.this, selectedPosition); selectedPosition = -1; restoreSelectedView(); } }); break; case R.id.action_edit: selectedTemplate.editItem(this, selectedPosition); selectedPosition = -1; restoreSelectedView(); break; case R.id.action_save: openBottomSheet(LayoutInflater.from(TemplateEditor.this).inflate(R.layout.bottom_sheet_view, null)); break; case R.id.action_simulate: startSimulator(); break; case android.R.id.home: onBackPressed(); break; default: //do nothing break; } return true; }