I want the editText firstname and the email field editText to be filled in correctly. The validation button which is disabled initially should become enabled (especially for the email address in [email protected] format). I tried with textWatcher but I didn't understand how to use it
editText1.addTextChangedListener(object: TextWatcher {
override fun onTextChanged(s:CharSequence, start:Int, before:Int, count:Int) {
if (s.toString().trim({ it <= ' ' }).isEmpty())
{
button.setEnabled(false)
}
else
{
button.setEnabled(true)
}
}
override fun beforeTextChanged(s:CharSequence, start:Int, count:Int,
after:Int) {
// TODO Auto-generated method stub
}
override fun afterTextChanged(s: Editable) {
// TODO Auto-generated method stub
}
})
You basically need to use, LiveData for the validation checks.
create a dataclass, something like
use LiveData object, say,
whenever an error occurs assign errors to _dataValidity and observe dataValidity. if no error occurs and after all the variables such as email and name have been checked you can assign isDataValid to true and after that do as you wish.
Use text watcher, and if there are errors assign them to the null values.
Try using the code below, I use this code to verify whether E-mail is valid or not.