这些方法有什么区别吗?我想首先创建对话框,以便在视图中单击某些内容时将其引用以解除它。显然,如果我使用构建器设置视图并且尚未创建警报,那是不可能的。
答案 0 :(得分:1)
根据AlertDialog.Builder source,它没有任何区别。
答案 1 :(得分:1)
“我想首先创建对话框,以便我可以参考 当在视图中点击某些内容时将其关闭。“
在您向对象显示对话之前,用户无法单击以关闭对话框,这是在您创建实例之后。请参阅下面的生命周期示例:
View someView = ...;
View someOtherView= ...;
AlertDialog.Builder builder = new AlertDialog.Builder(this);
//sets the view, but doesn't show anything.
builder.setView(someView);
//now we have an instance of AlertDialog, still not shown
AlertDialog dialog = builder.create();
//now we showed it
dialog.show();
//...(wait some time)
//now we changed its view after being shown
dialog.setView(someOtherView);