Check Mobile App
Read now
Start a Project

Android: Applying Text Watcher on an EditText

Save

In android you can apply TextWatcher on an EditText and perform action based on changes in the EditText. It is particularly useful when you want to perform some action while the user is entering text like auto save feature of text or suggestion feature. So in that case we can apply a TextWatcher and attach the methods we want to perform on text change.

There are three methods of TextWatcher we can use based on our need.

a. beforeTextChanged( CharSequence s, int start, int count, int after )

This method is used to notify you that in the CharSequence s, count number of character that start at start are about to be changed with a new text having after number of characters.

b. onTextChanged( CharSequence s, int start, int before, int count)

It is just the reverse of earlier one. This method is used to notify you that in the CharSequence s, count number of character that start at start are already been changed with older text having before number of characters.

c. afterTextChanged(Editable s)

It is the mostly used method as it performs after the text is changed and we generally have to perform something when the text is changes like saving it for the user. Some people perform text changes in this method and if you do so be careful that you don’t end up in an infinite loop as after any change to the text this method is again called.

I had used it to save the value of the text so that the user always get the updated value and loss of the data can be prevented. Below is the dummy code:

 

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

css.php

The support is fast and do everything in their power to make it perfect. If you need customization it's also done right away. I had massive research to select Mobikul and now I'm sure it was the right one.

Igor Souza

Igor Souza

Talk to Sales

Global

Live Chat
Start a Project

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home