Questions tagged [textwatcher]

TextWatcher is an interface in the Android SDK that can be attached to an Editable object to see when that Editable's text changes.

The android.text.TextWatcher Java interface is implemented by objects attached to an widget on . It exposes three methods, each of this methods will be called at a certain moment of the text being modified (for example: after the text is changed). Care must be taken when using the TextWatcher's methods to avoid getting into an infinite loop or to incorrectly modify the text.

625 questions
5
votes
1 answer

Formatting EditText phone number as user types

I'd like to edit an EditText field content everytime the user types a new character. Basically I want to format a phone number using libphonenumber. I implemented a TextWatcher that reads the field content and formats it into the phone format. But…
Guilherme
  • 7,839
  • 9
  • 56
  • 99
5
votes
2 answers

Letter Spacing in EditText for Android

I am trying to have a custom EditText based on the background that i am using for. The Background image has some spaces between the entry areas so i need to have some space between the characters(kerning) to fit them right in. So for example after…
koraxis
  • 801
  • 2
  • 12
  • 22
5
votes
7 answers

Adding a Dash in the editText automatically in Android

Have a look at my codes: txt_HomeNo.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { boolean flag = true; String eachBlock[]…
user2400937
5
votes
2 answers

Infinite loop error EditText

Firstly look my code : These are in my activity; EditText text1,text2; (Are defined corretly not problem) text1.addTextChangedListener(new MyTextWatcher(onePercent)); text2.addTextChangedListener(new MyTextWatcher(twoPercent)); .. …
Twinsens
  • 417
  • 6
  • 23
5
votes
1 answer

TextWatcher.afterTextChanged has incorrect string after backspace

I am using a TextWatcher to listen to key inputs. When user types '@', I open up a listactivity and user has to choose from the list. Once choosen, I place the selected item's text(including the initial @) to the edittext and normal editing goes on.…
droidbee
  • 134
  • 2
  • 16
5
votes
2 answers

Clickable compound drawable in EditText that pops a view on click

I am using TextWatcher to validate my input and I want my red hint image to be clickable so I can give the user visual feedback as shown in the image below. What I have until now is the edit text with the red hint image appearing when I enter…
Nouran H
  • 1,992
  • 5
  • 18
  • 24
4
votes
1 answer

EditText not updated after text changed in the TextWatcher

I have an EditText and a TextWatcher. Skeleton of my code: EditText x; x.addTextChangedListener(new XyzTextWatcher()); XyzTextWatcher implements TextWatcher() { public synchronized void afterTextChanged(Editable text) { …
Karthz
  • 53
  • 1
  • 2
  • 7
4
votes
1 answer

Undo/Redo, how to handle doOnTextChanged and doBeforeTextChanged in TextField of Jetpack Compose?

I need to implement redo/undo for TextField in Jetpack Compose. For an EditText I used this one and it worked well. However, for Jetpack Compose there is no such a listener. I would implement an own one based on that one for EditText, but I'm…
Mark Delphi
  • 1,376
  • 1
  • 11
  • 29
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
1 answer

Using a TextWatcher on a EditText to calculate the total and sum total in real time in android?

Here i want to take the default value coming from my database and setText to that value and calculate the net rate and total or else if the user edits the rate or making charges i would like to calculate the net rate and total based on that value in…
AndroidNewBee
  • 744
  • 3
  • 12
  • 36
4
votes
2 answers

TextWatcher.onTextChanged called multiple times

I've read a few threads about this problem, but couldn't find a thorough answer. I have a ListView with 3 rows, each contains a TextView and an EditText, and a custom adapter that extends BaseAdapter. Here's the adapter's getView…
Neria Nachum
  • 1,519
  • 1
  • 20
  • 37
4
votes
4 answers

Using PhoneNumberFormattingTextWatcher without typing country calling code

In the login panel of my app, I divided the country calling code and the remaining numbers in two editable TextView as below: I want to use international formatting standard in the TextView on the right. If a user who has a phone number as…
Dorukhan Arslan
  • 2,676
  • 2
  • 24
  • 42
4
votes
4 answers

Listview with edittext and textwatcher. Textwatcher fires multiple times (more than 3 times)

I have a custom list adapter with one list item having three edit texts. And I Have a date picker for one of them. When a date is set, the corressponding model for the adapter is saved with the date correctly. But for the other edit texts, i just…
Robin Rex
  • 210
  • 3
  • 10
4
votes
1 answer

Textwatcher not working on KitKat for number as inputType

I am trying to use a custom ViewGroup for my app. In that I am using the following xml to be inflated in my ViewGroup class.
Ram
  • 845
  • 1
  • 13
  • 26
4
votes
3 answers

EditText, How can control the cursor in TextWatcher?

I have a TextWatcher on an EditText, in the method afterTextChanged, I add characters to the EditText then I move the cursor to the end of EditText for continue adding text, but I have problems with that. Like this: public void…
José Castro
  • 3,976
  • 2
  • 22
  • 26