当我按customLayout中定义的按钮时,我想关闭Anko对话框
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()
不幸的是,我尝试了上面的代码,但是在我的dialog
中找不到对onClickListener
的引用。你有解决的办法吗?
答案 0 :(得分:2)
您可以在之前声明变量并分配HEAD
:
null
当然,现在您的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()
变量是可变的并且是可选的。