相关疑难解决方法(0)

Kotlin - 禁用“单位转换”功能

我仍然是 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)

android kotlin

3
推荐指数
1
解决办法
1720
查看次数

标签 统计

android ×1

kotlin ×1