Sam
10/05/2018, 3:59 PMdialog = with( AlertDialog.Builder( this ) ) {
setTitle( "foo" )
setMessage( "bar" )
setCancelable(true)
create()
}.also {
it.show()
}
or
dialog = AlertDialog.Builder( this ).run {
setTitle( "foo" )
setMessage( "bar" )
setCancelable(true)
create()
}.also {
it.show()
}
dalexander
10/05/2018, 4:25 PMwith
slightly more but I don’t have a strong opinionSam
10/05/2018, 4:27 PMapoorv9990
10/05/2018, 4:41 PMapply
when I am initializing something and setting things up
val dialog = AlertDialog.Builder(this).apply {
setTitle( "foo" )
setMessage( "bar" )
setCancelable(true)
}.show()
Sam
10/05/2018, 4:46 PMapoorv9990
10/05/2018, 4:47 PMshow()
gives you the dialog?Sam
10/05/2018, 4:47 PMSam
10/05/2018, 4:47 PMSam
10/05/2018, 4:48 PMVladyslav Sitalo
10/05/2018, 4:54 PMalso
at the end, you can just do .show
directlyapoorv9990
10/05/2018, 4:55 PMshow()
I have used in my code is `AlertDialog.Builder`’s show()
, since apply
will return the Builder
, which does return the AlertDialog
Sam
10/05/2018, 4:55 PMSam
10/05/2018, 4:59 PMSam
10/05/2018, 5:00 PMAndreas Sinz
10/05/2018, 5:00 PMval dialog = AlertDialog.Builder(this).apply {
setTitle( "foo" )
setMessage( "bar" )
setCancelable(true)
}.create()
.show()
hudsonb
10/05/2018, 5:00 PMSam
10/05/2018, 5:08 PModay
10/07/2018, 10:10 AModay
10/07/2018, 10:10 AManstaendig
10/08/2018, 9:12 AM