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
3
votes
1 answer

Cannot delete contents in editText with backSpace?

There is an editText with textWatcher applied. As you see in the below Gif, I cannot delete the numbers from end of the EditText, but first. When locale is english everything works fine, but not in arabic language.
Davoud
  • 2,576
  • 1
  • 32
  • 53
3
votes
2 answers

android editText inside expandableList wrong index and wrong count?

I got editText inside Expandable List to be the number of childcount according to the result of the editText to be edited. But editText position is always coming in different or childcount coming wrong and I get this…
3
votes
1 answer

notifyDataSetHasChanged() throws an error when used inside TextWatcher.onTextChanged() inside a RecyclerView

I'm building an app that allows user to have a real time base-conversion of a number. Users input their number in an edit text, and they choose the base using plus and minus button. The problem I encountered so far is providing the real time…
3
votes
1 answer

How Edittext can accept only two numbers after decimal point

I am trying to add only two numbers after a decimal point input in an EditText. So I implemented a TextWatcher to check the string during input. The function I am using below works amazing but has one major flaw. When you input any value,then you…
Steve Kamau
  • 2,755
  • 10
  • 42
  • 73
3
votes
2 answers

Custom phone number format (XXX-XXX-XXXX) TextWatcher getting stuck

Things is Working: The format (XXX-XXX-XXXX) which I want in phone number EditText is worked. Problem is: While deleting character "-" ,It can't deleted. I am getting stuck. PhoneNumberTextWatcher.java import android.text.Editable; import…
pRaNaY
  • 24,642
  • 24
  • 96
  • 146
3
votes
0 answers

Edittext call afterTextChanged only if user modified it and not the program

I am new to android and having some trouble with this method and wondering if someone can assist with this. Question: I have an array adapter with EditText box that the user can modify in the ListView. But, I only want user modifications and not the…
3
votes
2 answers

Unable to maintain the state of a custom dialog button when screen orientation changes

I have a customized dialog which i have created using DialogFragment. it uses a view which got one button and an edittext. in my edittext, i have implemented a textwatcher where if there are values in the edittext, the button becomes visible else it…
3
votes
6 answers

Set text color for a specific text in Android Edittext

If user types a String and it contains @ I want to change the color of the text to red. I have tried with textwatcher but got stack overflow error. I want to change the color only if the @ is at the beginning. The code is given…
user1767260
  • 1,543
  • 8
  • 26
  • 51
2
votes
1 answer

Avoid EditText TextWatcher firing events on every character change

I use an EditText textField with TextWatcher attached. All of the callback methods fire events on every character I enter. In my case I call an api on text changed, to put the response into a label on the same fragment. I can not check the EditText…
S. Gissel
  • 1,788
  • 2
  • 15
  • 32
2
votes
1 answer

2 TextWatchers for 1 EditText

I'm working on a simple android app project for myself. I found an article that made me decided to use TextWatcher. So simply, I add TextWatcher into my code. But here's the thing. I have designed 2 RadioButtons and 1 EditText. Both RadioButton will…
Anne
  • 31
  • 1
  • 6
2
votes
0 answers

afterTextChanged() event callback of TextWatcher gets invoked even when the user does not tap on the EditText field

I have an EditText field in my application and have a TextWatcher associated with it. The afterTextChanged() event callback gets invoked even when the user does not tap on the EditText to edit it. I need to check if the user has edited the EditText…
2
votes
1 answer

How to get ViewModel observer to not observe initially?

I have a SearchView icon on the Toolbar via onCreateOptionsMenu(Menu menu). A click on the icon creates an EditText line for the user to enter search inputs. I have a TextWatcher() attached to the EditText line so that when text is added to the…
AJW
  • 1,578
  • 3
  • 36
  • 77
2
votes
1 answer

DecimalFormat issue with EditText Input

Hello i'm writing this program to get user input and format to 0,000.00 for example the program works fine when i try 5,768.80 BUT it doesn't when i try 5,768.08 as you can see the problem is that i can't put a 0 in the cents place before any other…
2
votes
1 answer

TextWatcher on Android Oreo duplicate characters

In my application i have a fragment with a EditText that implements a textWatcher to set a mask...It works fine Android before 27 (Oreo), but on Oreo i notice sometimes it not works properly...like it was called twice Even if i just…
2
votes
2 answers

Android: How to use same edittext for username and phone number

Problem: User should be able to login either by their Phone number or username (something they have set during registration). Both of these values would allow user to sign in. The Edittext field needs to be smart enough to determine what is being…
1
2
3
13 14