Implementing Text Watcher for EditText

Try like this. EditText et = (EditText)findViewById(R.id.editText); Log.e(“TextWatcherTest”, “Set text xyz”); et.setText(“xyz”); et.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable s) { Log.e(“TextWatcherTest”, “afterTextChanged:\t” +s.toString()); } });

How to remove all listeners added with addTextChangedListener

There is no way to do this using current EditText interface directly. I see two possible solutions: Redesign your application so you always know what TextWatcher are added to particular EditText instance. Extend EditText and add possibility to clear all watchers. Here is an example of second approach – ExtendedEditText: public class ExtendedEditText extends EditText … Read more

TextWatcher for more than one EditText

Suggested solution in @Sebastian Roth’s answer is not one instance of TextWatcher for some EditTexts. It is one class and n instances of that class for n EditTexts. Each EditText has its own Spannable. TextWatcher‘s events has this Spannable as s parameter. I check their hashCode (unique Id of each object). myEditText1.getText() returns that Spannable. … Read more

How to use the TextWatcher class in Android?

For use of the TextWatcher… et1.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // TODO Auto-generated method stub } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // TODO Auto-generated method stub } @Override public void afterTextChanged(Editable s) { // TODO Auto-generated method stub … Read more