面膜与电话号码格式为NaN一个EditText像PhoneNumberUtils [英] Mask an EditText with Phone Number Format NaN like in PhoneNumberUtils

查看:605
本文介绍了面膜与电话号码格式为NaN一个EditText像PhoneNumberUtils的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用户输入的电话号码中的每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.

推荐答案

最容易做到这一点的方法是使用内置的Andr​​oid的<一个href="http://developer.android.com/reference/android/telephony/PhoneNumberFormattingTextWatcher.html">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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆