anko icon indicating copy to clipboard operation
anko copied to clipboard

Dismissing Anko Dialog in onClickListener

Open qbait opened this issue 6 years ago • 2 comments

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?

qbait avatar Oct 22 '18 14:10 qbait

You would get the reference of dialog in it

mrhammadasif avatar Nov 27 '18 07:11 mrhammadasif

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()

iceboundrock avatar Dec 18 '18 08:12 iceboundrock