How use extension function with anonymous class and lambda?
eg:
TextView has this extension function: (addTextChangedListener)
inline fun TextView.addTextChangedListener(
crossinline beforeTextChanged: (
text: CharSequence?,
start: Int,
count: Int,
after: Int
) -> Unit = { _, _, _, _ -> },
crossinline onTextChanged: (
text: CharSequence?,
start: Int,
count: Int,
after: Int
) -> Unit = { _, _, _, _ -> },
crossinline afterTextChanged: (text: Editable?) -> Unit = {}
): TextWatcher {
val textWatcher = object : TextWatcher {
override fun afterTextChanged(s: Editable?) {
afterTextChanged.invoke(s)
}
override fun beforeTextChanged(text: CharSequence?, start: Int, count: Int, after: Int) {
beforeTextChanged.invoke(text, start, count, after)
}
override fun onTextChanged(text: CharSequence?, start: Int, before: Int, count: Int) {
onTextChanged.invoke(text, start, before, count)
}
}
addTextChangedListener(textWatcher)
return textWatcher
}
I can use this extension function with lambda like:
myTextView.addTextChangedListener {
}
How I call afterTextChanged, beforeTextChanged and onTextChanged using that?