class TestView(view: View) {
val view = view
private lateinit var listener: (String) -> Unit
init {
view.onClick {
if (::listener.isInitialized) {
listener("test")
}
}
}
fun setTestListener(listener: (String) -> Unit) {
this@TestView.listener = listener
}
}
调用
var myView = TestView()
myView.setTestListener {
Logcat.d(it)
}