Android App Development
iOS App Development
Flutter App Development
Cross Platform App Development
Hire on-demand project developers and turn your idea into working reality.
Big thanks to Webkul and his team for helping get Opencart 3.0.3.7 release ready!
Deniel Kerr
Founder. Opencart
Top Partners
TextWatcher
EditText uses TextWatcher interface to watch change made over EditText. For doing this, EditText calls the addTextChangedListener() method.
In this way, we can check all change while modify text in EditText in android. But if there is need to check multiple EditText in single screen, then we have to add multiple TextWatcher for every EditText and manage a lot of lines. So we can make dynamic TextWatcher, that solve our problems.
Dynamic TextWatcher:-
In DynamicTextWatcher, we have to extends TextWatcher class and override its methods.
But this implementation still requires you to pass empty lambda for the function that you didn’t use. We can again leverage kotlin feature by making the parameter as optional parameter. The only thing we need to do is giving the parameters default value.
Thus, we can use it for any edit_text like this:-
In this way, we can rectify a lot of boilerplate code from our class and it will also look pretty.
We can do more centralize code and extract the onChanged into a single val resulting the final code to become like this:-
For more detail, you can reference:-
https://developer.android.com/reference/android/text/TextWatcher
We use cookies to personalize your experience. By continuing to visit this website you agree to our use of cookies. Learn more about privacy policy
Webkul is a truly trusted and supported IT Company to develop business ideas for e-commerce. They provide professional support after deploying the solution to production and be responsible to act for fixing the reported issues or system errors. We highly encourage to deal with Webkul for business development.
Hussein Zawia
Co-founder, 24Dokan
USA
India
Global
Name
Email
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.