我仍然是 Kotlin 的相对新手,经过一番挖掘后,无法解决看起来很简单的问题。对于下面的代码,编译器返回: 对于“function = PositiveButtonClick”和 function = negativeButtonClick”,功能“单位转换”被禁用
为什么?我需要做什么?
谢谢
called with MessageBox(context, "Hello Test", "My Message");
fun MessageBox(contxt: Context?, title: String, message: String): Boolean {
val builder = AlertDialog.Builder(contxt)
with(builder) {
setTitle(title)
setMessage(message)
setPositiveButton("YES", DialogInterface.OnClickListener(function = positiveButtonClick))
setNegativeButton("NO", DialogInterface.OnClickListener(function = negativeButtonClick))
show()
}
return false
}
val positiveButtonClick = { dialog: DialogInterface, which: Int -> Unit
Log.i("Dialog", "Yes")
}
val negativeButtonClick = { dialog: DialogInterface, which: Int -> Unit
Log.i("Dialog", "No")
}
Run Code Online (Sandbox Code Playgroud)