Created
March 26, 2021 07:50
-
-
Save iscomad/b091a60d243bfdf83b6a240a0152eb41 to your computer and use it in GitHub Desktop.
Helpful EditText extension functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Triggers an action when user finishes editing | |
*/ | |
fun EditText.doAfterTextEditingFinished(editingFinished: (String) -> Unit) { | |
var isEditing = false | |
doAfterTextChanged { | |
if (!isEditing && hasFocus()) { | |
isEditing = true | |
} | |
} | |
setOnFocusChangeListener { _, hasFocus -> | |
if (isEditing && !hasFocus) { | |
isEditing = false | |
editingFinished(text.toString()) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment