本文介绍了警报对话框不会关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在下面的代码片段中 alertdialog.dismiss
不起作用不知道为什么.日志工作正常,但对话框不会关闭.覆盖乐趣 onReceive(context: Context, arg1: Intent) {
In the below code snippet alertdialog.dismiss
is not working don't know why. Logs work fine but the dialog does not dismiss. override fun onReceive(context: Context, arg1: Intent) {
var builder = AlertDialog.Builder(context)
.setTitle("Network Error !")
.setMessage("Check your internet connection...")
.setCancelable(false)
var alertDialog:AlertDialog = builder.create()
if (isConnectedOrConnecting(context)) {
alertDialog.dismiss()
Log.i("Network","Alive")
} else{
Log.i("Network","Dead")
alertDialog.show()
//alertDialog.dismiss()
}
}
推荐答案
问题已解决.
在我们调用alert.show的地方初始化builder.create
Problem Solved.
Initialize the builder.create in the place where we call alert.show
var alertDialog:AlertDialog? = null
override fun onReceive(context: Context, arg1: Intent) {
var dialogBuilder = AlertDialog.Builder(context).setTitle("Network Error !")
.setCancelable(false)
.setMessage("Check your internet connection...")
if (isConnectedOrConnecting(context)) {
//initializeDialog(context)
alertDialog!!.dismiss()
Log.i("Network","Alive")
}else{
alertDialog = dialogBuilder.create()
alertDialog!!.show()
Log.i("Network","Dead")
//initializeDialog(context).create()
}
}
这篇关于警报对话框不会关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!