我在将 Kotlin 版本升级到1.3-M1或1.3-M2
我现在正在使用1.2.51,当我尝试使用任何较新版本时遇到的错误1.3-M2是:
Could not find org.jetbrains.kotlin:kotlin-gradle-plugin:1.3-M2.
我猜它已被移动,但我已经查看并没有找到解决方案。
任何人都可以指出我正确的方向吗?
我试图建立一个内联函数 setOnFocusChangeListener
这是我到目前为止所得到的:
inline fun EditText.onFocusChange(crossinline hasFocus: (Boolean) -> Unit) {
setOnFocusChangeListener(View.OnFocusChangeListener { view, b -> })
}
Run Code Online (Sandbox Code Playgroud)
我这样使用
freightTimeOfDay.onFocusChange { doSomething() }
Run Code Online (Sandbox Code Playgroud)
不幸的是,尽管它没有给我带来任何错误,doSomething()却从未被调用。
我在这里寻找两件事:
1-在其中获取一个参数,以便将其传递给doSomething()。例如
freightTimeOfDay.onFocusChange { doSomething(hasFocus) }
Run Code Online (Sandbox Code Playgroud)
2-使它工作:p,因为现在什么也没有发生。
更新:
好像Kotlin已经为此提供了某种内联类型
editText.setOnFocusChangeListener { view, b -> doSomething(b) }
Run Code Online (Sandbox Code Playgroud)
但是,这对我也不起作用,doSomething(hasFocus: Boolean)从未调用过。
提前致谢!