我正在try 构建一个setOnFocusChangeListener
的内联函数
This is what I got so far:
inline fun EditText.onFocusChange(crossinline hasFocus: (Boolean) -> Unit) {
setOnFocusChangeListener(View.OnFocusChangeListener { view, b -> })
}
我就是这样用的
freightTimeOfDay.onFocusChange { doSomething() }
不幸的是,虽然它没有给我错误,但doSomething()
永远不会被调用.
I'm looking for two things here:
1 - Get a param in there so I can pass it on to doSomething(). For example
freightTimeOfDay.onFocusChange { doSomething(hasFocus) }
2 - Make it work :p, as right now nothing is happening.
Update:
Seems like kotlin already has some type of inline for this
editText.setOnFocusChangeListener { view, b -> doSomething(b) }
However this isn't working for me either, doSomething(hasFocus: Boolean)
is never called.
Thanks in advance!