在越来越XXX-XXX-XXXX格式的手机号码在android系统的EditText箱 [英] getting phone number in XXX-XXX-XXXX format from edittext box in android

查看:442
本文介绍了在越来越XXX-XXX-XXXX格式的手机号码在android系统的EditText箱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我写在哪个用户在编辑文本框中输入电话号码的机器人。
我想数字是在XXX-XXX-XXXX的形式,这意味着' - '应该自动进入用户进入前3个字母,并陆续 -

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 '-'

我用的EditText ANUM =(EditText上)findViewById(R.id.altnum);
        anum.addTextChangedListener(新PhoneNumberFormattingTextWatcher());

但它进入格式输入所有数字之后。我想改变来当用户在输入数据一样,如果他preSS 123连字符应该自动进入
请告诉我如何做到这一点。

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.

感谢你

此致

ChinniKrishna Kothapalli

ChinniKrishna Kothapalli

推荐答案

一个选项是实现自己的输入过滤

One option is to implement your own InputFilter.

您可以在这里用我的答案:<一href=\"http://stackoverflow.com/questions/5798140/$p$pss-many-times-validate-ip-address-in-edittext-while-typing/5798188#5798188\">$p$pss &QUOT;&QUOT;很多次(打字时验证在EditText上的IP地址)这里:<一href=\"http://stackoverflow.com/questions/5736833/how-to-set-edittext-view-allow-only-two-numeric-values-and-two-decimal-values-lik/5738176#5738176\">How设置EDITTEXT视图只允许两个数值和像##两位十进制值。## 关于如何打字时分析文本的例子。

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

这篇关于在越来越XXX-XXX-XXXX格式的手机号码在android系统的EditText箱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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