I\'ve used some apps where when I fill my username, then go to my password, if I hit \"Done\" on the keyboard, the login form is automatically submitted, without me having t
Extend EditText:
fun EditText.onSubmit(func: () -> Unit) {
setOnEditorActionListener { _, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_DONE) {
func()
}
true
}
}
Then use the new method like this:
editText.onSubmit { submit() }
Where submit() is something like this:
fun submit() {
// call to api
}
fun EditText.on(actionId: Int, func: () -> Unit) {
setOnEditorActionListener { _, receivedActionId, _ ->
if (actionId == receivedActionId) {
func()
}
true
}
}
And then you can use it to listen to your event:
email.on(EditorInfo.IME_ACTION_NEXT, { confirm() })