The base way to handle it in Kotlin is:
edittext.setOnEditorActionListener { _, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_DONE) {
callback.invoke()
true
}
false
}
Use this to just call edittext.onDone{/*action*/}
in your main code. Makes your code far more readable and maintainable
fun EditText.onDone(callback: () -> Unit) {
setOnEditorActionListener { _, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_DONE) {
callback.invoke()
true
}
false
}
}
<EditText ...
android:imeOptions="actionDone"
android:inputType="text"/>
If you need
inputType="textMultiLine"
support, read this post