anko
anko copied to clipboard
Dismissing Anko Dialog in onClickListener
I would like to dismiss Anko Dialog when pressing the button defined in my customView
val dialog = alert {
val view = layoutInflater.inflate(R.layout.match_stats, null)
val closeButton = view.findViewById<ImageButton>(R.id.closeButton)
closeButton.setOnClickListener { _ -> dialog.dismiss()}
customView = view
}
dialog.show()
I tried above code, unfortunately, I can’t get a reference to dialog in my onClickListener. Do you have any idea how to solve it?
You would get the reference of dialog in it
it is impossible since the type of dialog is AlertBuilder<DialogInterface>
which does not have a dismiss
method.
I have an ulgry solution like this:
var dialog: DialogInterface? = null
dialog = alert {
val view = layoutInflater.inflate(R.layout.match_stats, null)
val closeButton = view.findViewById<ImageButton>(R.id.closeButton)
closeButton.setOnClickListener { _ -> dialog?.dismiss() }
customView = view
}.show()