I am making a simple Address Book app (targeting 4.2) that takes name, address, city, state, zip and phone.
I want to format the phone number input as a phone number
Maybe below sample project helps you;
https://github.com/reinaldoarrosi/MaskedEditText
That project contains a view class call MaskedEditText
. As first, you should add it in your project.
Then you add below xml part in res/values/attrs.xml file of project;
Then you will be ready to use MaskedEditText
view.
As last, you should add MaskedEditText in your xml file what you want like below;
Of course that, you can use it programmatically.
After those steps, adding MaskedEditText
will appear like below;
As programmatically, if you want to take it's text value as unmasked, you may use below row;
maskedEditText.getText(true);
To take masked value, you may send false
value instead of true
value in the getText
method.