Hi I am writing an android in which user enters phone number in an edit text box. I want the number to be in the form of xxx-xxx-xxxx that means '-' should come automatically after user enters first 3 letters and another '-'
I used EditText anum= (EditText)findViewById(R.id.altnum);
anum.addTextChangedListener(new PhoneNumberFormattingTextWatcher());
but it is coming into format only after all the digits are entered. I want the change to come when the user was entering the data like if he press 123 a hypen should come automatically Please tell me how to do this.
Thanking You
Yours Sincerely
ChinniKrishna Kothapalli
Following Code works adding and deleting scenario's fine but logic is some what longer :
Recently, I had a requirement for the same. I tried this with TextWatcher. Sharing here with a hope that Someone else may need later.
Thanks
JRH
One option is to implement your own InputFilter.
You can use my answers here: press "." many times (validate ip address in EditText while typing) and here: How to set Edittext view allow only two numeric values and two decimal values like ##.## for examples on how to parse the text while typing.
If you want the dashes to appear automatically, you will need to add them to the return of your filter method