Java Code Examples for android.app.AlertDialog.Builder#create()
The following examples show how to use
android.app.AlertDialog.Builder#create() .
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 int msg, final int title, final int yes, final int no, 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(yes, lOk); builder.setNegativeButton(no, lCancel); // builder.setCancelable(false); final AlertDialog alert = builder.create(); alert.show(); return alert; }
Example 2
Source File: MMAlert.java From wechatsdk-xamarin with Apache License 2.0 | 6 votes |
public static AlertDialog showAlert(final Context context, final String title, final String msg, final View view, 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.setTitle(title); builder.setMessage(msg); builder.setView(view); builder.setPositiveButton(R.string.app_ok, lOk); builder.setNegativeButton(R.string.app_cancel, lCancel); // builder.setCancelable(true); builder.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (lCancel != null) { lCancel.onClick(dialog, 0); } } }); final AlertDialog alert = builder.create(); alert.show(); return alert; }
Example 3
Source File: InputTextDialog.java From Android-POS with MIT License | 6 votes |
public InputTextDialog(Context context, OnOkClickListener listener) { mListener = listener; LayoutInflater inflater = LayoutInflater.from(context); View view = inflater.inflate(R.layout.dialog_input, null); final EditText textEt = (EditText) view.findViewById(R.id.editText); Builder builder = new AlertDialog.Builder(context); builder.setTitle("Input Text"); builder.setView(view) .setPositiveButton("Print", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String text = textEt.getText().toString(); if (mListener != null && !text.equals("")) { mListener.onPrintClick(text); } } }); mDialog = builder.create(); }
Example 4
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 String yes, final String no, 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(yes, lOk); builder.setNegativeButton(no, lCancel); // builder.setCancelable(false); final AlertDialog alert = builder.create(); alert.show(); return alert; }
Example 5
Source File: MMAlert.java From wechatsdk-xamarin with Apache License 2.0 | 6 votes |
public static AlertDialog showAlert(final Context context, final int msgId, final int titleId, 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(titleId); builder.setMessage(msgId); 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 6
Source File: Notification.java From reader with MIT License | 5 votes |
@SuppressLint("NewApi") private void changeTextDirection(Builder dlg){ int currentapiVersion = android.os.Build.VERSION.SDK_INT; dlg.create(); AlertDialog dialog = dlg.show(); if (currentapiVersion >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) { TextView messageview = (TextView)dialog.findViewById(android.R.id.message); messageview.setTextDirection(android.view.View.TEXT_DIRECTION_LOCALE); } }
Example 7
Source File: MyOverlays.java From codeexamples-android with Eclipse Public License 1.0 | 5 votes |
protected boolean onTap(int index) { OverlayItem overlayItem = overlays[index]; Builder builder = new AlertDialog.Builder(context); 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 true; }
Example 8
Source File: Notification.java From reader with MIT License | 5 votes |
@SuppressLint("NewApi") private void changeTextDirection(Builder dlg){ int currentapiVersion = android.os.Build.VERSION.SDK_INT; dlg.create(); AlertDialog dialog = dlg.show(); if (currentapiVersion >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) { TextView messageview = (TextView)dialog.findViewById(android.R.id.message); messageview.setTextDirection(android.view.View.TEXT_DIRECTION_LOCALE); } }
Example 9
Source File: Notification.java From reader with MIT License | 5 votes |
@SuppressLint("NewApi") private void changeTextDirection(Builder dlg){ int currentapiVersion = android.os.Build.VERSION.SDK_INT; dlg.create(); AlertDialog dialog = dlg.show(); if (currentapiVersion >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) { TextView messageview = (TextView)dialog.findViewById(android.R.id.message); messageview.setTextDirection(android.view.View.TEXT_DIRECTION_LOCALE); } }
Example 10
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 11
Source File: Notification.java From reader with MIT License | 5 votes |
@SuppressLint("NewApi") private void changeTextDirection(Builder dlg){ int currentapiVersion = android.os.Build.VERSION.SDK_INT; dlg.create(); AlertDialog dialog = dlg.show(); if (currentapiVersion >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) { TextView messageview = (TextView)dialog.findViewById(android.R.id.message); messageview.setTextDirection(android.view.View.TEXT_DIRECTION_LOCALE); } }
Example 12
Source File: CustomedDialog.java From evercam-android with GNU Affero General Public License v3.0 | 5 votes |
public static AlertDialog getSelectNewOwnerDialog(final Activity activity, final ArrayList<String> usernameList) { CharSequence[] listCharArray = usernameList.toArray(new CharSequence[usernameList.size()]); Builder dialogBuilder = new AlertDialog.Builder(activity) .setNegativeButton(R.string.cancel, null); if (usernameList.size() > 0) { dialogBuilder.setSingleChoiceItems(listCharArray, 0, null) .setPositiveButton(R.string.transfer, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { ListView listView = ((AlertDialog) dialog).getListView(); Object checkedItem = listView.getAdapter().getItem(listView .getCheckedItemPosition()); String selectedUsername = checkedItem.toString(); if (activity instanceof SharingActivity) { TransferOwnershipTask.launch(activity, SharingActivity .evercamCamera.getCameraId(), selectedUsername); } } }).setTitle(R.string.transfer_select_title); } else { dialogBuilder.setMessage(R.string.msg_share_before_transfer); } return dialogBuilder.create(); }
Example 13
Source File: DialogUtils.java From RxAndroidBootstrap with Apache License 2.0 | 5 votes |
/** * Show a model dialog box. The <code>android.app.AlertDialog</code> object is returned so that * you can specify an OnDismissListener (or other listeners) if required. * <b>Note:</b> show() is already called on the AlertDialog being returned. * * @param context The current Context or Activity that this method is called from. * @param message Message to display in the dialog. * @return AlertDialog that is being displayed. */ public static AlertDialog quickDialog(final Activity context, final String message) { final SpannableString s = new SpannableString(message); //Make links clickable Linkify.addLinks(s, Linkify.ALL); Builder builder = new AlertDialog.Builder(context); builder.setMessage(s); builder.setPositiveButton(android.R.string.ok, closeDialogListener()); AlertDialog dialog = builder.create(); dialog.show(); ((TextView) dialog.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance()); //Make links clickable return dialog; }
Example 14
Source File: BusActivity.java From BaiduMap-TrafficAssistant with MIT License | 5 votes |
/** * * 这是点击搜索按钮后,从服务器返回公交信息;在这里得到route值; */ @Override public void onGetBusLineResult(BusLineResult result) { if (result == null || result.error != SearchResult.ERRORNO.NO_ERROR) { Toast.makeText(BusActivity.this, "抱歉,未找到结果", Toast.LENGTH_LONG) .show(); return; } mBaiduMap.clear(); route = result; nodeIndex = -1; BusLineOverlay overlay = new BusLineOverlay(mBaiduMap); mBaiduMap.setOnMarkerClickListener(overlay); overlay.setData(result); overlay.addToMap(); overlay.zoomToSpan(); mBtnPre.setVisibility(View.VISIBLE); mBtnNext.setVisibility(View.VISIBLE); Toast.makeText(context, result.getBusLineName(), Toast.LENGTH_SHORT) .show(); Log.i("TAG", "总站数:" + result.getStations().size() + ""); // 在这里最好使用对话框的形式把公交信息显示出来; String message = ""; Builder builder = new Builder(context); builder.setTitle("为您查询到的地铁信息:"); for (int i = 0; i < result.getStations().size(); i++) { message = message + "地铁" + (i + 1) + ":" + result.getStations().get(i).getTitle() + "\n"; } builder.setMessage(city_return + result.getBusLineName() + "共有" + result.getStations().size() + "个地铁站:" + "\n" + message); builder.setPositiveButton("确定", null); AlertDialog alertDialog = builder.create(); alertDialog.show(); }
Example 15
Source File: CustomedDialog.java From evercam-android with GNU Affero General Public License v3.0 | 5 votes |
/** * Return a pop up dialog that shows camera snapshot. * * @param bitmap the returned image Bitmap to show in pop up dialog */ public static AlertDialog getSnapshotDialog(final Activity activity, Bitmap bitmap) { Builder builder = new AlertDialog.Builder(activity); final AlertDialog snapshotDialog = builder.create(); snapshotDialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent); LayoutInflater mInflater = LayoutInflater.from(activity); final View snapshotView = mInflater.inflate(R.layout.dialog_test_snapshot, null); Button nextButton = (Button) snapshotView.findViewById(R.id.connect_camera_next_button); if (activity instanceof AddCameraActivity) { nextButton.setVisibility(View.VISIBLE); nextButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ((AddCameraActivity) activity).showCameraNameView(); snapshotDialog.dismiss(); } }); } ImageView snapshotImageView = (ImageView) snapshotView.findViewById(R.id .test_snapshot_image); snapshotImageView.setImageBitmap(bitmap); snapshotDialog.setView(snapshotView); return snapshotDialog; }
Example 16
Source File: SettingsActivity.java From qBittorrent-Controller with MIT License | 4 votes |
public void genericOkDialog(int title, int message, DialogInterface.OnClickListener okListener) { if (!isFinishing()) { Builder builder = new Builder(this); // Title if (title != -1) { builder.setTitle(title); } // Message builder.setMessage(message); // Ok builder.setPositiveButton(R.string.ok, okListener); // Create dialog AlertDialog dialog = builder.create(); // Show dialog dialog.show(); } }
Example 17
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 18
Source File: EnableLocationDialogFragment.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); mMessageId = savedInstanceState.getInt(DialogKeys.MESSAGE_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); mMessageParams = savedInstanceState .getStringArray(DialogKeys.MESSAGE_PARAMS); } final Builder builder = new Builder(getActivity(), mTheme); if ((mTitleId == 0) && (mMessageId == 0)) { throw new IllegalArgumentException("No Title and no message"); } if (mMessageId != 0) { if ((mMessageParams != null) && (mMessageParams.length > 0)) { builder.setMessage(getActivity() .getString(mMessageId, (Object[]) mMessageParams)); } else { builder.setMessage(mMessageId); } } 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 19
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 20
Source File: MapActivity.java From BaiduMap-TrafficAssistant with MIT License | 4 votes |
@Override public void onReceiveLocation(BDLocation location) { MyLocationData data = new MyLocationData.Builder()// .direction(mCurrentX)// .accuracy(location.getRadius())// .latitude(location.getLatitude())// .longitude(location.getLongitude())// .build(); mBaiduMap.setMyLocationData(data); // 设置自定义图标 MyLocationConfiguration config = new MyLocationConfiguration( mLocationMode, true, mIconLocation); mBaiduMap.setMyLocationConfigeration(config); // 更新经纬度 mLatitude = location.getLatitude(); mLongitude = location.getLongitude(); if (isFirstIn) { LatLng latlng = new LatLng(location.getLatitude(), location.getLongitude()); MapStatusUpdate msu = MapStatusUpdateFactory.newLatLng(latlng); mBaiduMap.animateMapStatus(msu); isFirstIn = false; Toast.makeText(context, location.getAddrStr(), Toast.LENGTH_SHORT).show(); Log.i("TAG", location.getAddrStr() + "\n" + location.getAltitude() + "" + "\n" + location.getCity() + "\n" + location.getCityCode() + "\n" + location.getCoorType() + "\n" + location.getDirection() + "\n" + location.getDistrict() + "\n" + location.getFloor() + "\n" + location.getLatitude() + "\n" + location.getLongitude() + "\n" + location.getNetworkLocationType() + "\n" + location.getProvince() + "\n" + location.getSatelliteNumber() + "\n" + location.getStreet() + "\n" + location.getStreetNumber() + "\n" + location.getTime() + "\n"); // 弹出对话框显示定位信息; Builder builder = new Builder(context); builder.setTitle("为您获得的定位信息:"); builder.setMessage("当前位置:" + location.getAddrStr() + "\n" + "城市编号:" + location.getCityCode() + "\n" + "定位时间:" + location.getTime() + "\n" + "当前纬度:" + location.getLatitude() + "\n" + "当前经度:" + location.getLongitude()); builder.setPositiveButton("确定", null); AlertDialog alertDialog = builder.create(); alertDialog.show(); }// if }