Code example for AlertDialog.Builder

Methods: create, setCancelable, setIcon, setMessage, setTitle

0
	private Toast toast;
	 
	@Override 
	public AlertDialog show(Context context, String title, String message) {
		AlertDialog.Builder builder = makeBuilder(context);
		builder.setTitle(title);
		 
		if(drawables != null) {
			builder.setIcon(drawables.getDrawable("socialize_icon_white.png"));
		} 
		 
		if(!StringUtils.isEmpty(message)) {
			builder.setMessage(message);
		} 
		 
		builder.setCancelable(true)
		.setPositiveButton("OK", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int id) {
				dialog.dismiss();
			} 
		}); 
		 
		AlertDialog alert = builder.create();
		 
		// Register to prevent window leakage 
		DialogRegistration.register(context, alert);
		 
		alert.show();
		 
		return alert;
	} 
	 
	public void showToast(Context context, String message) {
		if(toast != null) {
			toast.cancel();
		} 
		toast = Toast.makeText(context, message, Toast.LENGTH_SHORT);
		toast.show();
	} 
	 
	protected Builder makeBuilder(Context context) {
		return new AlertDialog.Builder(context);
	} 
 
	public void setDrawables(Drawables drawables) {
		this.drawables = drawables;
	} 
Contextual code suggestions in your IDE  Get Codota for Java