Last active
April 28, 2021 17:09
-
-
Save shahharshil0/f9bd345f7243a6bb556f9a3a4639ff27 to your computer and use it in GitHub Desktop.
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
fun TextInputEditText.isNotNullOrEmpty(errorString: String): Boolean { | |
val textInputLayout = this.parent.parent as TextInputLayout | |
textInputLayout.errorIconDrawable = null | |
this.onChange { textInputLayout.error = null } | |
return if (this.text.toString().trim().isEmpty()) { | |
textInputLayout.error = errorString | |
false | |
} else { | |
true | |
} | |
} | |
fun EditText.isNotNullOrEmpty(errorString: String): Boolean { | |
this.onChange { this.error = null } | |
return if (this.text.toString().trim().isBlank()) { | |
this.error = errorString | |
false | |
} else { | |
true | |
} | |
} | |
fun EditText.onChange(cb: (String) -> Unit) { | |
this.addTextChangedListener(object : TextWatcher { | |
override fun afterTextChanged(s: Editable?) { | |
cb(s.toString()) | |
} | |
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {} | |
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {} | |
}) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment