AlertDialog.builder的obj.create()vs obj.show()vs obj.create().show()之间的区别

dru*_*abs 7 android android-alertdialog

AlertDialog的构建器类的.create()和.show()方法之间有什么区别吗?就像我们使用以下方法创建警报对话框时

AlertDialog.Builder builder = new 
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setMessage("");
builder.setPositiveButton(....)
builder.setNegativeButton(....)
Run Code Online (Sandbox Code Playgroud)

什么是推荐使用的实践,为什么?

builder.create() //I have seen this creates and displays the dialog
Run Code Online (Sandbox Code Playgroud)

要么

builder.show() //this also displays the dialog
Run Code Online (Sandbox Code Playgroud)

要么

builder.create().show() //well same thing
Run Code Online (Sandbox Code Playgroud)

我已阅读文档.但无法从中得到任何意义.有任何想法吗 ?

Sam*_*iya 5

obj.create()-For create Dialog

obj.show()-For show Dialog < - 如果没有它,你就不能在创建时显示对话框.

和

obj.create().show()-create and show Dialog i mean both same as above two in one statement.

  • @KKD吧!创建不会"显示"你的对话.实际上,Builders`show()`首先调用`create()`.... (3认同)