Java Code Examples for android.app.AlertDialog.Builder#setPositiveButton()
The following examples show how to use
android.app.AlertDialog.Builder#setPositiveButton() .
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: MMAlert.java From wechatsdk-xamarin with Apache License 2.0 | 6 votes |
public static AlertDialog showAlert(final Context context, final String msg, final String title, final DialogInterface.OnClickListener lOk, final DialogInterface.OnClickListener lCancel) { if (context instanceof Activity && ((Activity) context).isFinishing()) { return null; } final Builder builder = new AlertDialog.Builder(context); builder.setIcon(R.drawable.ic_dialog_alert); builder.setTitle(title); builder.setMessage(msg); builder.setPositiveButton(R.string.app_ok, lOk); builder.setNegativeButton(R.string.app_cancel, lCancel); // builder.setCancelable(false); final AlertDialog alert = builder.create(); alert.show(); return alert; }
Example 2
Source File: CustomedDialog.java From evercam-android with GNU Affero General Public License v3.0 | 6 votes |
/** * Return a pop up dialog that ask the user whether or not to save the snapshot */ public static AlertDialog getConfirmSnapshotDialog(Activity activity, Bitmap bitmap, DialogInterface.OnClickListener listener) { Builder snapshotDialogBuilder = new AlertDialog.Builder(activity); LayoutInflater mInflater = LayoutInflater.from(activity); final View snapshotView = mInflater.inflate(R.layout.dialog_confirm_snapshot, null); ImageView snapshotImageView = (ImageView) snapshotView.findViewById(R.id .confirm_snapshot_image); snapshotImageView.setImageBitmap(bitmap); snapshotDialogBuilder.setView(snapshotView); snapshotDialogBuilder.setPositiveButton(activity.getString(R.string.save), listener); snapshotDialogBuilder.setNegativeButton(activity.getString(R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); AlertDialog snapshotDialog = snapshotDialogBuilder.create(); snapshotDialog.setCanceledOnTouchOutside(false); return snapshotDialog; }
Example 3
Source File: MMAlert.java From wechatsdk-xamarin with Apache License 2.0 | 6 votes |
public static AlertDialog showAlert(final Context context, final String msg, final String title) { if (context instanceof Activity && ((Activity) context).isFinishing()) { return null; } final Builder builder = new AlertDialog.Builder(context); builder.setIcon(R.drawable.ic_dialog_alert); builder.setTitle(title); builder.setMessage(msg); builder.setPositiveButton(R.string.app_ok, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { dialog.cancel(); } }); final AlertDialog alert = builder.create(); alert.show(); return alert; }
Example 4
Source File: CustomedDialog.java From evercam-android with GNU Affero General Public License v3.0 | 6 votes |
/** * The prompt dialog that ask for a preset name */ public static AlertDialog getCreatePresetDialog(final VideoActivity videoActivity, final String cameraId) { Builder dialogBuilder = new AlertDialog.Builder(videoActivity); LayoutInflater inflater = LayoutInflater.from(videoActivity); final View view = inflater.inflate(R.layout.dialog_create_preset, null); final EditText editText = (EditText) view.findViewById(R.id.create_preset_edit_text); dialogBuilder.setView(view); dialogBuilder.setPositiveButton(R.string.add, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String presetName = editText.getText().toString(); if (!presetName.isEmpty()) { new CreatePresetTask(videoActivity, cameraId, presetName) .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } } }); dialogBuilder.setNegativeButton(R.string.cancel, null); return dialogBuilder.create(); }
Example 5
Source File: BaseActivity.java From Viewer with Apache License 2.0 | 5 votes |
public void openDialogMessage(int title,int message){ final Builder builder = new AlertDialog.Builder(this); builder.setTitle(title); builder.setMessage(message); builder.setCancelable(true); builder.setPositiveButton(R.string.ok_btn, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { builder.create().dismiss(); } }); builder.show(); }
Example 6
Source File: NumberGroupEdit.java From callmeter with GNU General Public License v3.0 | 5 votes |
/** * Show dialog to edit the group name. */ private void showNameDialog() { final Uri u = ContentUris.withAppendedId(DataProvider.NumbersGroup.CONTENT_URI, gid); Cursor c = getContentResolver().query(u, DataProvider.NumbersGroup.PROJECTION, null, null, null); String name = null; if (c.moveToFirst()) { name = c.getString(DataProvider.NumbersGroup.INDEX_NAME); } c.close(); final Builder builder = new Builder(this); final EditText et = new EditText(this); et.setText(name); builder.setView(et); builder.setTitle(R.string.name_); builder.setCancelable(true); builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialog, final int id) { ContentValues values = new ContentValues(); values.put(DataProvider.NumbersGroup.NAME, et.getText().toString()); NumberGroupEdit.this.getContentResolver().update(u, values, null, null); CallMeter.setActivitySubtitle(NumberGroupEdit.this, et.getText().toString()); } }); builder.setNegativeButton(android.R.string.cancel, null); builder.show(); }
Example 7
Source File: HourGroupEdit.java From callmeter with GNU General Public License v3.0 | 5 votes |
/** * Show dialog to edit the group name. */ private void showNameDialog() { final Uri u = ContentUris.withAppendedId(DataProvider.HoursGroup.CONTENT_URI, gid); Cursor c = getContentResolver().query(u, DataProvider.HoursGroup.PROJECTION, null, null, null); String name = null; if (c.moveToFirst()) { name = c.getString(DataProvider.NumbersGroup.INDEX_NAME); } c.close(); final Builder builder = new Builder(this); final EditText et = new EditText(this); et.setText(name); builder.setView(et); builder.setTitle(R.string.name_); builder.setCancelable(true); builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialog, final int id) { ContentValues values = new ContentValues(); values.put(DataProvider.NumbersGroup.NAME, et.getText().toString()); HourGroupEdit.this.getContentResolver().update(u, values, null, null); CallMeter.setActivitySubtitle(HourGroupEdit.this, et.getText().toString()); } }); builder.setNegativeButton(android.R.string.cancel, null); builder.show(); }
Example 8
Source File: AlertExampleActivity.java From codeexamples-android with Eclipse Public License 1.0 | 5 votes |
@Override protected Dialog onCreateDialog(int id) { switch (id) { case DIALOG_ALERT: // Create out AlterDialog Builder builder = new AlertDialog.Builder(this); builder.setMessage("This will end the activity"); builder.setCancelable(true); builder.setPositiveButton("I agree", new OkOnClickListener()); builder.setNegativeButton("No, no", new CancelOnClickListener()); AlertDialog dialog = builder.create(); dialog.show(); } return super.onCreateDialog(id); }
Example 9
Source File: MMAlert.java From wechatsdk-xamarin with Apache License 2.0 | 5 votes |
public static AlertDialog showAlert(final Context context, final String title, final String ok, final View view, final DialogInterface.OnClickListener lOk) { if (context instanceof Activity && ((Activity) context).isFinishing()) { return null; } final Builder builder = new AlertDialog.Builder(context); builder.setTitle(title); builder.setView(view); builder.setPositiveButton(ok, lOk); // builder.setCancelable(true); final AlertDialog alert = builder.create(); alert.show(); return alert; }
Example 10
Source File: ThemeListPreference.java From droidddle with Apache License 2.0 | 5 votes |
@Override protected void onPrepareDialogBuilder(Builder builder) { entries = getEntries(); entryValues = getEntryValues(); if (entries == null || entryValues == null || entries.length != entryValues.length) { throw new IllegalStateException("ListPreference requires an entries array and an entryValues array which are both the same length"); } mEntryIndex = findIndexOfValues(getValue(), entryValues); OnClickListener listener = new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { mEntryIndex = which; // setSummary(getColorSummary(mEntryIndex)); editor.putString(getKey(), entryValues[which].toString()).commit(); /* * Clicking on an item simulates the positive button click, and * dismisses the dialog. */ if (mThemeListener != null) { mThemeListener.onPreferenceChange(ThemeListPreference.this, which); } ThemeListPreference.this.onClick(dialog, DialogInterface.BUTTON_POSITIVE); dialog.dismiss(); } }; ThemeListPreferenceAdapter adapter = new ThemeListPreferenceAdapter(mContext); builder.setSingleChoiceItems(adapter, mEntryIndex, listener); /* * The typical interaction for list-based dialogs is to have * click-on-an-item dismiss the dialog instead of the user having to * press 'Ok'. */ builder.setPositiveButton(null, null); }
Example 11
Source File: SanaUtil.java From sana.mobile with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Creates a message dialog. * * @param context the current Context * @param title the dialog title * @param message the dialog message * @return a new dialogf for alerting the user. */ public static AlertDialog createDialog(Context context, String title, String message) { Builder dialogBuilder = new Builder(context); dialogBuilder.setPositiveButton(context.getResources().getString( R.string.general_ok), null); dialogBuilder.setTitle(title); dialogBuilder.setMessage(message); return dialogBuilder.create(); }
Example 12
Source File: ListPreference.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
@Override protected void onPrepareDialogBuilder(Builder builder) { super.onPrepareDialogBuilder(builder); if (mEntries == null || mEntryValues == null) { throw new IllegalStateException( "ListPreference requires an entries array and an entryValues array."); } mClickedDialogEntryIndex = getValueIndex(); builder.setSingleChoiceItems(mEntries, mClickedDialogEntryIndex, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { mClickedDialogEntryIndex = which; /* * Clicking on an item simulates the positive button * click, and dismisses the dialog. */ ListPreference.this.onClick(dialog, DialogInterface.BUTTON_POSITIVE); dialog.dismiss(); } }); /* * The typical interaction for list-based dialogs is to have * click-on-an-item dismiss the dialog instead of the user having to * press 'Ok'. */ builder.setPositiveButton(null, null); }
Example 13
Source File: ActivityMain.java From LibreTasks with Apache License 2.0 | 5 votes |
public void onClick(View v) { Builder help = new AlertDialog.Builder(v.getContext()); help.setTitle(R.string.help_title); help.setIcon(R.drawable.icon); help.setMessage(Html.fromHtml(getString(R.string.help_activitymain))); help.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }); help.show(); }
Example 14
Source File: ActivityMain.java From LibreTasks with Apache License 2.0 | 5 votes |
/** * Display our about dialog. */ private void showAbout() { // Get package information String version; try { PackageInfo pkgInfo; pkgInfo = getPackageManager().getPackageInfo(this.getPackageName(), 0); version = pkgInfo.versionName; } catch (NameNotFoundException e) { version = getString(R.string.unknown); } StringBuilder message = new StringBuilder(); message.append(getString(R.string.about_desc)).append("<br /><br />"); message.append(getString(R.string.copyright)).append("<br /><br />"); message.append(getString(R.string.about_version)).append(" ").append(version); message.append("<br /><br />"); message.append(getString(R.string.about_license)).append("<br /><br />"); message.append(getString(R.string.about_website)); Builder about = new AlertDialog.Builder(this); about.setTitle(R.string.about_title); about.setIcon(R.drawable.icon); about.setMessage(Html.fromHtml(message.toString())); about.setPositiveButton(R.string.ok, null); about.show(); }
Example 15
Source File: LoginActivity.java From ThirdPartyLoginDemo with MIT License | 5 votes |
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // 显示提示 Builder builder = new Builder(LoginActivity.this); builder.setTitle(R.string.if_register_needed); builder.setMessage(R.string.after_auth); builder.setPositiveButton(R.string.tpl_ok, new OnClickListener() { public void onClick(DialogInterface dialog, int which) { showDemo(); finish(); } }); builder.create().show(); }
Example 16
Source File: InCallActivity.java From CSipSimple with GNU General Public License v3.0 | 5 votes |
@Override public void run() { Builder builder = new Builder(InCallActivity.this); Resources r = getResources(); builder.setTitle("ZRTP supported by remote party"); builder.setMessage("Do you confirm the SAS : " + sasString); builder.setPositiveButton(r.getString(R.string.yes), this); builder.setNegativeButton(r.getString(R.string.no), this); AlertDialog backupDialog = builder.create(); backupDialog.show(); }
Example 17
Source File: ConfirmAPIActivity.java From android with GNU General Public License v3.0 | 4 votes |
@Override protected void onResume() { super.onResume(); try { mPackage = getCallingPackage(); if (mPackage == null) { finish(); return; } PackageManager pm = getPackageManager(); ApplicationInfo app = pm.getApplicationInfo(mPackage, 0); View view = View.inflate(this, R.layout.api_confirm, null); ((ImageView) view.findViewById(R.id.icon)).setImageDrawable(app.loadIcon(pm)); ((TextView) view.findViewById(R.id.prompt)).setText( getString(R.string.prompt, app.loadLabel(pm), getString(R.string.app))); ((CompoundButton) view.findViewById(R.id.check)).setOnCheckedChangeListener(this); Builder builder = new AlertDialog.Builder(this); builder.setView(view); builder.setIconAttribute(android.R.attr.alertDialogIcon); builder.setTitle(android.R.string.dialog_alert_title); builder.setPositiveButton(android.R.string.ok, this); builder.setNegativeButton(android.R.string.cancel, this); mAlert = builder.create(); mAlert.setCanceledOnTouchOutside(false); mAlert.setOnShowListener(new OnShowListener() { @Override public void onShow(DialogInterface dialog) { mButton = mAlert.getButton(DialogInterface.BUTTON_POSITIVE); mButton.setEnabled(false); } }); //setCloseOnTouchOutside(false); mAlert.show(); } catch (Exception e) { Log.e(TAG, "onResume", e); finish(); } }
Example 18
Source File: MainActivity.java From BaiduMap-TrafficAssistant with MIT License | 4 votes |
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { switch (position) { case 0: Intent intent_map = new Intent(context, MapActivity.class); startActivity(intent_map); overridePendingTransition(R.anim.come_in, R.anim.come_out); break; case 1: Intent intent_bus = new Intent(context, BusActivity.class); startActivity(intent_bus); overridePendingTransition(R.anim.come_in, R.anim.come_out); break; case 2: Intent intent_download = new Intent(context, DownloadActivity.class); startActivity(intent_download); overridePendingTransition(R.anim.come_in, R.anim.come_out); break; case 3: Intent intent_navigate = new Intent(context, NavigationActivity.class); startActivity(intent_navigate); overridePendingTransition(R.anim.come_in, R.anim.come_out); break; case 4: break; case 5: break; case 6: // Intent intent_chat = new Intent(context, ChatActivity.class); // startActivity(intent_chat); // overridePendingTransition(R.anim.come_in, R.anim.come_out); break; case 7: break; case 8: // Intent intent_face = new Intent(context, FaceActivity.class); // startActivity(intent_face); // overridePendingTransition(R.anim.come_in, R.anim.come_out); break; case 9: Intent intent_browser = new Intent(context, BrowserActivity.class); startActivity(intent_browser); overridePendingTransition(R.anim.come_in, R.anim.come_out); break; case 10: Intent intent_dial = new Intent(context, DialActivity.class); startActivity(intent_dial); overridePendingTransition(R.anim.come_in, R.anim.come_out); break; case 11: Builder builder = new Builder(context); builder.setTitle("关于"); builder.setMessage("城市交通智能助手" + "\n" + "版本:1.0" + "\n" + "开发者:陈宇峰"); builder.setPositiveButton("确定", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); AlertDialog alertDialog = builder.create(); alertDialog.show(); break; } }
Example 19
Source File: AddUserInfoDialogFragment.java From barterli_android with Apache License 2.0 | 4 votes |
@Override public Dialog onCreateDialog(final Bundle savedInstanceState) { if (savedInstanceState != null) { mTitleId = savedInstanceState.getInt(DialogKeys.TITLE_ID); mNegativeLabelId = savedInstanceState .getInt(DialogKeys.NEGATIVE_LABEL_ID); mNeutralLabelId = savedInstanceState .getInt(DialogKeys.NEUTRAL_LABEL_ID); mPositiveLabelId = savedInstanceState .getInt(DialogKeys.POSITIVE_LABEL_ID); isCancellable = savedInstanceState .getBoolean(DialogKeys.CANCELLABLE); mIconId = savedInstanceState.getInt(DialogKeys.ICON_ID); mTheme = savedInstanceState.getInt(DialogKeys.THEME); } final Builder builder = new Builder(getActivity(), mTheme); final View contentView = LayoutInflater.from(getActivity()) .inflate(R.layout.layout_dialog_names, null); mFirstNameEditText = (EditText) contentView .findViewById(R.id.edittext_first_name); mLastNameEditText = (EditText) contentView .findViewById(R.id.edittext_last_name); builder.setView(contentView); if (mIconId != 0) { builder.setIcon(mIconId); } if (mTitleId != 0) { builder.setTitle(mTitleId); } if (mPositiveLabelId != 0) { builder.setPositiveButton(mPositiveLabelId, mClickListener); } if (mNegativeLabelId != 0) { builder.setNegativeButton(mNegativeLabelId, mClickListener); } if (mNeutralLabelId != 0) { builder.setNeutralButton(mNeutralLabelId, mClickListener); } builder.setCancelable(isCancellable); setCancelable(isCancellable); return builder.create(); }
Example 20
Source File: UpdaterDialogManager.java From TurkcellUpdater_android_sdk with Apache License 2.0 | 4 votes |
private static void initializeMessageDialogButtons(final Activity activity, Builder builder, final Message message) { final boolean viewButtonTargetGooglePlay; boolean viewButtonEnabled = false; if (message != null) { if (message.targetGooglePlay && !Utilities.isNullOrEmpty(message.targetPackageName)) { viewButtonTargetGooglePlay = true; viewButtonEnabled = true; } else if (message.targetWebsiteUrl != null) { viewButtonEnabled = true; viewButtonTargetGooglePlay = false; } else { viewButtonTargetGooglePlay = false; } } else { viewButtonTargetGooglePlay = false; } if (!viewButtonEnabled) { if (message.description != null && message.description.get(MessageDescription.KEY_POSITIVE_BUTTON) != null) { builder.setNeutralButton(message.description.get(MessageDescription.KEY_POSITIVE_BUTTON), null); } else { builder.setNeutralButton(R.string.close, null); } } else { if (message.description != null && message.description.get(MessageDescription.KEY_NEGATIVE_BUTTON) != null) { builder.setNegativeButton(message.description.get(MessageDescription.KEY_NEGATIVE_BUTTON), null); } else { builder.setNegativeButton(R.string.close, null); } OnClickListener onClickListener = new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (viewButtonTargetGooglePlay) { openGooglePlayPage(activity, message.targetPackageName); } else { openWebPage(activity, message.targetWebsiteUrl); } } }; if (message.description != null && message.description.get(MessageDescription.KEY_POSITIVE_BUTTON) != null) { builder.setPositiveButton(message.description.get(MessageDescription.KEY_POSITIVE_BUTTON), onClickListener); } else { builder.setPositiveButton(R.string.view, onClickListener); } } }