Ok in my app I have a field for the user to input a number. I have the field set to only accept numbers. When the user clicks on the field it brings up the keyboard. On the
The base way to handle the done action in Kotlin is:
edittext.setOnEditorActionListener { _, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_DONE) {
// Call your code here
true
}
false
}
Use this to call edittext.onDone {/*action*/} in your main code. Keeps it more readable and maintainable
edittext.onDone { submitForm() }
fun EditText.onDone(callback: () -> Unit) {
setOnEditorActionListener { _, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_DONE) {
callback.invoke()
true
}
false
}
}
If you need
inputType="textMultiLine"support, read this post