Questions tagged [android-textwatcher]

For questions related with TextWatcher callback interface

A special interface, that allows watching of the Editable field contents.

Has three callback methods:

  • void afterTextChanged (Editable s)
    This method is called to notify you that, somewhere within s, the text has been changed.
  • 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.
  • 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.

Useful links

205 questions
129
votes
2 answers

Android TextWatcher.afterTextChanged vs TextWatcher.onTextChanged

Under what circumstances should I use afterTextChanged instead of onTextChanged and vice versa?
Will
  • 19,789
  • 10
  • 43
  • 45
59
votes
5 answers

Differences between TextWatcher 's onTextChanged, beforeTextChanged and afterTextChanged

In my Android project, I have had to add a TextChangedListener (TextWatcher) to an edit text view. And there are three parts to it: onTextChanged() beforeTextChanged() afterTextChanged() What are the differences of these three? I have had to…
Samantha Withanage
  • 3,811
  • 10
  • 30
  • 59
26
votes
3 answers

onTextChanged vs afterTextChanged in Android - Live examples needed

I was reading about TextWatcher in Android programming. I could not understand the difference between afterTextChanged() and onTextChanged(). Although I referred to Differences between TextWatcher 's onTextChanged, beforeTextChanged and…
SimpleGuy
  • 2,764
  • 5
  • 28
  • 45
6
votes
1 answer

TextWatcher onTextChanged not working with soft keyboard auto-complete / suggested words

I'm Implementing a TextWatcher on an EditText to find and underline a series of keywords within the text whenever a new character is entered by the user. However when a suggested / auto-complete word on the soft keyboard is selected, instead of…
5
votes
4 answers

How to update the same EditText using TextWatcher?

In my Android application I need to implement a TextWatcher interface to implement onTextChanged. The problem I have is, I want to update the same EditText With some extra string. When I try to do this the program terminates. final EditText ET =…
JibW
  • 4,538
  • 17
  • 66
  • 101
5
votes
4 answers

when setText on editText TextWatcher.onTextChanged not called

Whenever EditText string is changed, onTextChanged is called. Now when I start a new Activity and send data through Bundle, onTextChanged is not called. if( getIntent().getExtras() != null) { Bundle b = getIntent().getExtras(); int value =…
phpdroid
  • 1,642
  • 1
  • 18
  • 36
4
votes
3 answers

How to fill edittext with placeholders until it is not filled

I faced the following problem: I need to implement the solution for the case when the phone should be entered to the EditText. This phone should have non-removable part and last four numbers should be filled with underscore at the beginning and then…
4
votes
4 answers

TextWatcher - cursor goes back to the start of EditText

I've got the following TextWatcher definition: _textWatcher = new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void…
4
votes
3 answers

How to add Text Watcher on multiple Edit text in android?

I have an activity which contain two edit text and have a TextWatcher in that activity which is implemented separately. I want to make a single class which implements TextWatcher and that that TextWatcher in that edit text. How can I do…
vishwas
  • 251
  • 1
  • 3
  • 16
3
votes
1 answer

Inconsistent onTextChanged() behaviour

I wrote the code below to figure out how onTextChanged() method works: override fun onTextChanged(string: CharSequence?, start: Int, before: Int, count: Int) { Log.d(TAG, "onTextChanged triggered.") Log.d(TAG, "string…
3
votes
1 answer

Kotlin: EditText is null in afterTextChanged()

I have an EditText and I'm setting an error into it or dismiss the error after text changes. However somehow I'm getting NPE when trying to access the EditText from the afterTextChanged() method. phone_number_input.addTextChangedListener(object :…
3
votes
3 answers

Phone number auto formatting in android

I need to format a phone number in an edit text in android as per this format (222) 222-2222 ext222222 I have created a watcher that does the auto formatting for me. The watcher works fine and formats the phone number correctly. My only issue is…
Karu
  • 935
  • 2
  • 13
  • 32
3
votes
2 answers

How can I get new entered value on EditText with TextWatcher

I can get the old value. But I do not have a solution to get a new entered value. In fact, I want to separate the old value from the new value. For example: If oldText=hello and new entered EditText value equal to (hello w or w hello), I want…
Mr.Json
  • 139
  • 1
  • 2
  • 11
3
votes
0 answers

PhoneNumberFormattingTextWatcher not working for specific US phone number

I am using PhoneNumberFormattingTextWatcher to format the phone number in US format while it is being entered. However when we input a number 1111111111 it fails to format it. For other numbers such as 2222222222 it works fine. Eg: Input:…
Monica M
  • 161
  • 3
  • 12
3
votes
4 answers

Elegant way to enable/disable button depending on input in two or more EditText fields

I have read this question How to disable Button if EditText is empty ? But there it is only 1 EditText field. What is an elegant solution to use a TextWatcher to enable or disable a Button if both of two EditText fields are either empty or contain…
1
2 3
13 14