Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level
35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Ctors](https://developer.android.com/reference/android/telephony/PhoneNumberFormattingTextWatcher#pubctors) \| [Methods](https://developer.android.com/reference/android/telephony/PhoneNumberFormattingTextWatcher#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/telephony/PhoneNumberFormattingTextWatcher#inhmethods)

# PhoneNumberFormattingTextWatcher

*** ** * ** ***


`
public


class
PhoneNumberFormattingTextWatcher
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


implements

https://developer.android.com/reference/android/text/TextWatcher


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.telephony.PhoneNumberFormattingTextWatcher |

<br />

*** ** * ** ***


**This class was deprecated
in API level 35.**   

This is a thin wrapper on a \`libphonenumber\` \`AsYouTypeFormatter\`; it is recommended
to use that instead.

Watches a `https://developer.android.com/reference/android/widget/TextView` and if a phone number is entered
will format it.


Stop formatting when the user

- Inputs non-dialable characters
- Removes the separator in the middle of string.


The formatting will be restarted once the text is cleared.

## Summary

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/telephony/PhoneNumberFormattingTextWatcher#PhoneNumberFormattingTextWatcher()() ` The formatting is based on the current system locale and future locale changes may not take effect on this instance. |
| ` https://developer.android.com/reference/android/telephony/PhoneNumberFormattingTextWatcher#PhoneNumberFormattingTextWatcher(java.lang.String)(https://developer.android.com/reference/java/lang/String countryCode) ` The formatting is based on the given `countryCode`. |

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/telephony/PhoneNumberFormattingTextWatcher#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. |
| ` void` | ` https://developer.android.com/reference/android/telephony/PhoneNumberFormattingTextWatcher#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`. |
| ` void` | ` https://developer.android.com/reference/android/telephony/PhoneNumberFormattingTextWatcher#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`. |

| ### Inherited methods |
|---|---|
| From class ` https://developer.android.com/reference/java/lang/Object ` |---|---| | ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/lang/Object#clone()() ` Creates and returns a copy of this object. | | ` boolean` | ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Indicates whether some other object is "equal to" this one. | | ` void` | ` https://developer.android.com/reference/java/lang/Object#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | | ` final https://developer.android.com/reference/java/lang/Class<?>` | ` https://developer.android.com/reference/java/lang/Object#getClass()() ` Returns the runtime class of this `Object`. | | ` int` | ` https://developer.android.com/reference/java/lang/Object#hashCode()() ` Returns a hash code value for the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notify()() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notifyAll()() ` Wakes up all threads that are waiting on this object's monitor. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/lang/Object#toString()() ` Returns a string representation of the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait()() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*. | ||
| From interface ` https://developer.android.com/reference/android/text/TextWatcher ` |---|---| | ` 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 constructors

### PhoneNumberFormattingTextWatcher

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

```
public PhoneNumberFormattingTextWatcher ()
```

The formatting is based on the current system locale and future locale changes
may not take effect on this instance.

<br />

### PhoneNumberFormattingTextWatcher

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

```
public PhoneNumberFormattingTextWatcher (String countryCode)
```

The formatting is based on the given `countryCode`.


This method may take several seconds to complete, so it should
only be called from a worker thread.

<br />

| Parameters ||
|---|---|
| `countryCode` | `String`: the ISO 3166-1 two-letter country code that indicates the country/region where the phone number is being entered. <br /> |

## Public methods

### afterTextChanged

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

```
public 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 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 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 /> |