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

Android - Do something *after* text is changed in EditText

I build an android application. I have an EditText. I want to save changes (or anything else) automatically after the user change the text. Now I use editText.addTextChangedListener(textWatcher); and TextWatcher textWatcher = new TextWatcher()…
TamarG
  • 3,522
  • 12
  • 44
  • 74
15
votes
2 answers

Detect backspace in TextWatcher

I am using TextWatcher and I am unable to detect Backspace key in TextWatcher.afterTextChange event. I also want to clear textView on some condition in textWatcher event. public void afterTextChanged(Editable s) { // TODO Auto-generated method…
Jay Gajjar
  • 2,661
  • 2
  • 21
  • 35
15
votes
3 answers

Events of TextWatcher are being called twice

On my application I put TextWatcher on EditText. When I change the text of the EditText, the events of TextWatcher are being called twice. I am using emulator for running the app.
Jay Gajjar
  • 2,661
  • 2
  • 21
  • 35
14
votes
3 answers

android EditText ,keyboard textWatcher problem

I am working on a android app and I have an EditText where user can input numbers. I want to format the number using different currency formats (say ##,##,###) and I want to do it on the fly, ie when user enter each digit(not when enter is pressed).…
Krishnabhadra
  • 34,169
  • 30
  • 118
  • 167
14
votes
5 answers

How to only allow positive numbers in an EditText

I have a TextWatcher that enables a button when all the EditTexts length() are != 0. I now want to add the ability to also make sure the number is positive. I tried putting a new if() inside the other if() to check if >0 but for some reason it…
Getek99
  • 479
  • 2
  • 5
  • 18
14
votes
2 answers

How do I use AsYouTypeFormatter TextWatcher in Android App?

I am trying to use the AsYouTypeFormatter from Google's libphonenumber with TextWatcher and am not sure if it's possible. I have been able to format the text as typed from an EditText field and output it in another EditText but not able to change…
sugarwaffle
  • 551
  • 1
  • 5
  • 13
14
votes
4 answers

How to limit the text in numbers only from 0-59 in Edit Text in Android?

I have an Edit Text in which the number can only between 0-59, No other numbers will be typed in that Edit Text, I tried text-watcher but did not get success. Any idea? 12-26 14:59:39.715: E/AndroidRuntime(19494): FATAL EXCEPTION: main 12-26…
sumit acharya
  • 619
  • 1
  • 6
  • 18
13
votes
4 answers

Can't insert into Editable

I must be doing something obvious, but I can't figure out what it is. I'm simply trying to insert a character into an Editable: @Override public void afterTextChanged(Editable s) { Log.d(TAG, "inserting space at " + location); …
Shawn Lauzon
  • 6,234
  • 4
  • 35
  • 46
12
votes
3 answers

How to format the input of EditText when typing with thousands separators (,) in Android?

I've an edittext , it only gets numeric without decimal numbers. android:inputType="number" I want to separate thousands while I'm typing . For example 25,000 . I know I should use TextWatcher and I've used this code but I couldn't make it work…
12
votes
5 answers

PhoneNumberFormattingTextWatcher is not working

I am trying to use PhoneNumberFormattingTextWatcher but there is nothing happening as if the code is not there here is the code @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); …
Firas Shrourou
  • 625
  • 8
  • 19
11
votes
5 answers

How to change TextView text on DataChange without calling back a TextWatcher listener

Consider: TextView textView = new TextView(context); textView.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override …
Mohammad Ersan
  • 12,304
  • 8
  • 54
  • 77
11
votes
1 answer

How to use setSpan() in onTextChanged() to save parameters of onTextChanged()?

I am actually trying to do card formatting, for that I am trying to implement what google says from link You are not told where the change took place because other afterTextChanged() methods may already have made other changes and invalidated the…
T_C
  • 3,148
  • 5
  • 26
  • 46
11
votes
7 answers

Automatically add dash in phone number in Android

Instead of 5118710, it should be 511-8710. I'd like to add a dash after the user the user inputted 3 digits already in the EditText. The maximum length of the EditText is 7 digits only. After I figured out the above problem, I've got stuck in coding…
user2400937
11
votes
3 answers

How to Handle Enter Key Using TextWatcher on Android

I am working on Android. Previously i used onKeyListener to handle specific action on key event. However, this way seems not to solve my problem since almost all key would get disable once i have implemented that listener to my EditText. After…
M Rijalul Kahfi
  • 1,460
  • 3
  • 22
  • 42
10
votes
5 answers

IndexOutOfBoundsException setSpan (0 ... 1) ends beyond length 0

I am using this library for material editText with label: https://github.com/rey5137/Material/wiki/Text-Field nice library :) but... i am using next code to check are entered symbols correct: private boolean hasCorrectSymbols(String input){ …
1
2
3
41 42