// 非Android中的AlertDialog,便于说明问题,举个例子
public class AlertDialog {
private int width;
private int height;
private String title;
private String confirmText;
private String denyText;
private AlertDialog(){}
public AlertDialog(int width, int height){ // 空白的警告框
AlertDialog(width,height,null);
}
// 带标题的警告框
public AlertDialog(int width, int height, String title){ // 带标题的警告框
AlertDialog(width, height, title, "确定");
}
// 带标题的警告框,有确定按钮
public AlertDialog(int width, int height, String title, String confirm){
AlertDialog(width, height, title, confirm, null);
}
// 带标题的警告框,有确定按钮,取消按钮
public AlertDialog(int width, int height, String title, String confirm, String denyText){
// set every thing.
}
}
// 非Android中的AlertDialog,便于说明问题,举个例子
public class AlertDialog {
private int width;
private int height;
private String title;
private String confirmText;
private String denyText;
public AlertDialog(){}// 空白的构造函数
public void setWidth(int width){
this.width = width;
}
// 其他set方法
}
// 非Android中的AlertDialog,便于说明问题,举个例子
public class AlertDialog {
private int width;
private int height;
private String title;
private String confirmText;
private String denyText;
// private
private AlertDialog(){}
// Builder中使用
protected AlertDialog(Builder b){
width = b.width;
height = b.height;
// .....
if(width==0||height==0) throws new Exception("size must be set");
}
// 构造器
public static class Builder {
private int width;
private int height;
private String title;
private String confirmText;
private String denyText;
// 注意:返回的Builder。
public Builder setTitle(String title) {
this.title = title;
return this;
}
// 其他set...
public AlertDialog build(){
return AlertDialog(this);
}
}
}
new AlertDialog.Builder().setTitle("提示").build();
评论区