Stay organized with collections
Save and categorize content based on your preferences.
TextWatcher
public
interface
TextWatcher
implements
NoCopySpan
Known indirect subclasses
AbsListView |
Base class that can be used to implement virtualized lists of items.
|
ExpandableListView |
A view that shows items in a vertically scrolling two-level list.
|
GridView |
A view that shows items in two-dimensional scrolling grid.
|
ListView |
Displays a vertically-scrollable collection of views, where each view is positioned
immediately below the previous view in the list.
|
PasswordTransformationMethod |
|
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
|
afterTextChanged(Editable s)
This method is called to notify you that, somewhere within
s , the text has been changed.
|
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 .
|
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 .
|
Public methods
afterTextChanged
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 Spannable.setSpan
in onTextChanged(CharSequence, int, int, int)
to mark your place and then look up from here where the span
ended up.
beforeTextChanged
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.
Parameters |
s |
CharSequence |
start |
int |
count |
int |
after |
int |
onTextChanged
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.
Parameters |
s |
CharSequence |
start |
int |
before |
int |
count |
int |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-04-17 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-04-17 UTC."],[],[],null,["# TextWatcher\n\nAdded in [API level 1](/guide/topics/manifest/uses-sdk-element#ApiLevels) \nSummary: [Methods](#pubmethods) \n\nTextWatcher\n===========\n\n*** ** * ** ***\n\n[Kotlin](/reference/kotlin/android/text/TextWatcher \"View this page in Kotlin\") \\|Java\n\n\n`\npublic\n\n\ninterface\nTextWatcher\n`\n\n\n`\n\n\nimplements\n\n`[NoCopySpan](/reference/android/text/NoCopySpan)`\n\n\n`\n\n|--------------------------|\n| android.text.TextWatcher |\n\n|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Known indirect subclasses [AbsListView](/reference/android/widget/AbsListView), [ExpandableListView](/reference/android/widget/ExpandableListView), [GridView](/reference/android/widget/GridView), [ListView](/reference/android/widget/ListView), [PasswordTransformationMethod](/reference/android/text/method/PasswordTransformationMethod), [PhoneNumberFormattingTextWatcher](/reference/android/telephony/PhoneNumberFormattingTextWatcher) |---------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------| | [AbsListView](/reference/android/widget/AbsListView) | Base class that can be used to implement virtualized lists of items. | | [ExpandableListView](/reference/android/widget/ExpandableListView) | A view that shows items in a vertically scrolling two-level list. | | [GridView](/reference/android/widget/GridView) | A view that shows items in two-dimensional scrolling grid. | | [ListView](/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](/reference/android/text/method/PasswordTransformationMethod) | | | [PhoneNumberFormattingTextWatcher](/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.* | |\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nWhen an object of this type is attached to an Editable, its methods will\nbe called when the text is changed.\n\nSummary\n-------\n\n| ### Public methods ||\n|------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ` abstract void` | ` `[afterTextChanged](/reference/android/text/TextWatcher#afterTextChanged(android.text.Editable))`(`[Editable](/reference/android/text/Editable)` s) ` This method is called to notify you that, somewhere within `s`, the text has been changed. |\n| ` abstract void` | ` `[beforeTextChanged](/reference/android/text/TextWatcher#beforeTextChanged(java.lang.CharSequence,%20int,%20int,%20int))`(`[CharSequence](/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`. |\n| ` abstract void` | ` `[onTextChanged](/reference/android/text/TextWatcher#onTextChanged(java.lang.CharSequence,%20int,%20int,%20int))`(`[CharSequence](/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`. |\n\nPublic methods\n--------------\n\n### afterTextChanged\n\nAdded in [API level 1](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic abstract void afterTextChanged (Editable s)\n```\n\nThis method is called to notify you that, somewhere within\n`s`, the text has been changed.\nIt is legitimate to make further changes to `s` from\nthis callback, but be careful not to get yourself into an infinite\nloop, because any changes you make will cause this method to be\ncalled again recursively.\n(You are not told where the change took place because other\nafterTextChanged() methods may already have made other changes\nand invalidated the offsets. But if you need to know here,\nyou can use [Spannable.setSpan](/reference/android/text/Spannable#setSpan(java.lang.Object,%20int,%20int,%20int)) in [onTextChanged(CharSequence, int, int, int)](/reference/android/text/TextWatcher#onTextChanged(java.lang.CharSequence,%20int,%20int,%20int))\nto mark your place and then look up from here where the span\nended up.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|-----|-------------------|\n| `s` | `Editable` \u003cbr /\u003e |\n\n### beforeTextChanged\n\nAdded in [API level 1](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic abstract void beforeTextChanged (CharSequence s, \n int start, \n int count, \n int after)\n```\n\nThis method is called to notify you that, within `s`,\nthe `count` characters beginning at `start`\nare about to be replaced by new text with length `after`.\nIt is an error to attempt to make changes to `s` from\nthis callback.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|---------|-----------------------|\n| `s` | `CharSequence` \u003cbr /\u003e |\n| `start` | `int` \u003cbr /\u003e |\n| `count` | `int` \u003cbr /\u003e |\n| `after` | `int` \u003cbr /\u003e |\n\n### onTextChanged\n\nAdded in [API level 1](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic abstract void onTextChanged (CharSequence s, \n int start, \n int before, \n int count)\n```\n\nThis method is called to notify you that, within `s`,\nthe `count` characters beginning at `start`\nhave just replaced old text that had length `before`.\nIt is an error to attempt to make changes to `s` from\nthis callback.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|----------|-----------------------|\n| `s` | `CharSequence` \u003cbr /\u003e |\n| `start` | `int` \u003cbr /\u003e |\n| `before` | `int` \u003cbr /\u003e |\n| `count` | `int` \u003cbr /\u003e |"]]