android.app.AlertDialog.Builder#create ( )源码实例Demo

下面列出了android.app.AlertDialog.Builder#create ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Android-POS   文件: InputTextDialog.java
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();
}
 
源代码2 项目: wechatsdk-xamarin   文件: MMAlert.java
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;
}
 
源代码3 项目: wechatsdk-xamarin   文件: MMAlert.java
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;
}
 
源代码4 项目: wechatsdk-xamarin   文件: MMAlert.java
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;
}
 
源代码5 项目: wechatsdk-xamarin   文件: MMAlert.java
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;
}
 
源代码6 项目: evercam-android   文件: CustomedDialog.java
/**
 * 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;
}
 
源代码7 项目: BaiduMap-TrafficAssistant   文件: BusActivity.java
/**
 * 
 * 这是点击搜索按钮后,从服务器返回公交信息;在这里得到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();

}
 
源代码8 项目: RxAndroidBootstrap   文件: DialogUtils.java
/**
 * 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;
}
 
源代码9 项目: evercam-android   文件: CustomedDialog.java
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();
}
 
源代码10 项目: reader   文件: Notification.java
@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);
    }
}
 
源代码11 项目: reader   文件: Notification.java
@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);
    }
}
 
源代码12 项目: sana.mobile   文件: SanaUtil.java
/**
 * 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();
}
 
源代码13 项目: reader   文件: Notification.java
@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);
    }
}
 
源代码14 项目: reader   文件: Notification.java
@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);
    }
}
 
源代码15 项目: codeexamples-android   文件: MyOverlays.java
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;
}
 
源代码16 项目: BaiduMap-TrafficAssistant   文件: MapActivity.java
@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
}
 
源代码17 项目: BaiduMap-TrafficAssistant   文件: MainActivity.java
@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;

		}

	}
 
@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();
}
 
源代码19 项目: qBittorrent-Controller   文件: SettingsActivity.java
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();
        }

    }
 
@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();
}