Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Methods](https://developer.android.com/reference/android/text/TextWatcher#pubmethods)

# TextWatcher

*** ** * ** ***

` public interface TextWatcher `   
` implements https://developer.android.com/reference/android/text/NoCopySpan `

|---|
| android.text.TextWatcher |

Known indirect subclasses [AbsListView](https://developer.android.com/reference/android/widget/AbsListView), [ExpandableListView](https://developer.android.com/reference/android/widget/ExpandableListView), [GridView](https://developer.android.com/reference/android/widget/GridView), [ListView](https://developer.android.com/reference/android/widget/ListView), [PasswordTransformationMethod](https://developer.android.com/reference/android/text/method/PasswordTransformationMethod), [PhoneNumberFormattingTextWatcher](https://developer.android.com/reference/android/telephony/PhoneNumberFormattingTextWatcher) [AbsListView](https://developer.android.com/reference/android/widget/AbsListView) Base class that can be used to implement virtualized lists of items. [ExpandableListView](https://developer.android.com/reference/android/widget/ExpandableListView) A view that shows items in a vertically scrolling two-level list. [GridView](https://developer.android.com/reference/android/widget/GridView) A view that shows items in two-dimensional scrolling grid. [ListView](https://developer.android.com/reference/android/widget/ListView) Displays a vertically-scrollable collection of views, where each view is positioned immediately below the previous view in the list.
[PasswordTransformationMethod](https://developer.android.com/reference/android/text/method/PasswordTransformationMethod) [PhoneNumberFormattingTextWatcher](https://developer.android.com/reference/android/telephony/PhoneNumberFormattingTextWatcher) *This class was deprecated in API level 35. This is a thin wrapper on a \`libphonenumber\` \`AsYouTypeFormatter\`; it is recommended to use that instead.*   

*** ** * ** ***

When an object of this type is attached to an Editable, its methods will be called when the text is changed.

## Summary

| ### Public methods ||
|---|---|
| ` abstract void` | ` https://developer.android.com/reference/android/text/TextWatcher#afterTextChanged(android.text.Editable)(https://developer.android.com/reference/android/text/Editable s) ` This method is called to notify you that, somewhere within `s`, the text has been changed. |
| ` abstract void` | ` https://developer.android.com/reference/android/text/TextWatcher#beforeTextChanged(java.lang.CharSequence,%20int,%20int,%20int)(https://developer.android.com/reference/java/lang/CharSequence s, int start, int count, int after) ` This method is called to notify you that, within `s`, the `count` characters beginning at `start` are about to be replaced by new text with length `after`. |
| ` abstract void` | ` https://developer.android.com/reference/android/text/TextWatcher#onTextChanged(java.lang.CharSequence,%20int,%20int,%20int)(https://developer.android.com/reference/java/lang/CharSequence s, int start, int before, int count) ` This method is called to notify you that, within `s`, the `count` characters beginning at `start` have just replaced old text that had length `before`. |

## Public methods

### afterTextChanged

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract void afterTextChanged (Editable s)
```

This method is called to notify you that, somewhere within `s`, the text has been changed. It is legitimate to make further changes to `s` from this callback, but be careful not to get yourself into an infinite loop, because any changes you make will cause this method to be called again recursively. (You are not told where the change took place because other afterTextChanged() methods may already have made other changes and invalidated the offsets. But if you need to know here, you can use `https://developer.android.com/reference/android/text/Spannable#setSpan(java.lang.Object,%20int,%20int,%20int)` in `https://developer.android.com/reference/android/text/TextWatcher#onTextChanged(java.lang.CharSequence,%20int,%20int,%20int)` to mark your place and then look up from here where the span ended up.

<br />

| Parameters ||
|---|---|
| `s` | `Editable` <br /> |

### beforeTextChanged

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract void beforeTextChanged (CharSequence s, 
                int start, 
                int count, 
                int after)
```

This method is called to notify you that, within `s`, the `count` characters beginning at `start` are about to be replaced by new text with length `after`. It is an error to attempt to make changes to `s` from this callback.

<br />

| Parameters ||
|---|---|
| `s` | `CharSequence` <br /> |
| `start` | `int` <br /> |
| `count` | `int` <br /> |
| `after` | `int` <br /> |

### onTextChanged

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract void onTextChanged (CharSequence s, 
                int start, 
                int before, 
                int count)
```

This method is called to notify you that, within `s`, the `count` characters beginning at `start` have just replaced old text that had length `before`. It is an error to attempt to make changes to `s` from this callback.

<br />

| Parameters ||
|---|---|
| `s` | `CharSequence` <br /> |
| `start` | `int` <br /> |
| `before` | `int` <br /> |
| `count` | `int` <br /> |