问题描述
我想使用户输入的电话号码中的每EDITTEXT用户输入数字时,以动态改变的格式。也就是说,当用户输入4位数字,例如7144,的EDITTEXT显示714-4。我想EDITTEXT动态更新格式化### - ### - ####当用户输入一个数字。如何才能做到这一点?同时,我处理一个以上editTexts。
I want to make user inputted phone number in an editText to dynamically change format every time the user inputs a number. That is, when user inputs up to 4 digits, like 7144, the editText shows "714-4".I would like the editText to be dynamically updated to format ###-###-#### whenever the user inputs a digit. how can this be done? also, I am handling more than one editTexts.
推荐答案
最容易做到这一点的方法是使用内置的Android的PhoneNumberFormattingTextWatcher.
Easiest way to do this is to use the built in Android PhoneNumberFormattingTextWatcher.
所以基本上你得到你的EditText在code和设置您的文字守望这样的..
So basically you get your EditText in code and set your text watcher like this..
EditText inputField = (EditText) findViewById(R.id.inputfield);
inputField.addTextChangedListener(new PhoneNumberFormattingTextWatcher());
尼斯考虑使用PhoneNumberFormattingTextWatcher是它会根据你的区域设置正确格式化数字输入。
Nice think about using PhoneNumberFormattingTextWatcher is it will format your number entry correctly based on your locale.
这篇关于面膜与电话号码格式为NaN一个EditText像PhoneNumberUtils的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!