EditText Input type Issue

天涯浪子 提交于 2019-11-28 11:42:42

问题


There is a name EditText in my screen. I want to accept only alphabets means from a-z,A-Z and should not accept numbers, special chars.

I'am using inputtype="textPersonName" for that but its notworking, it accepts means showing all numbers, chars etc..

For phone field inputtype="phone" is working it accepting means showing numbers in field` only.

Why like that?


回答1:


Your best bet is to use an InputFilter to restrict the characters that are permitted in your EditText control. You should be able to easily adapt the answer from How do I use InputFilter to limit characters in an EditText in Android? to do what you require.




回答2:


You will need to subclass EditText and detect key events. Reject any character other than a-zA-Z This is the only way to limit the acceptable characters.

A person's name could contain a number so textPersonName is working correctly.




回答3:


Try using TYPE_TEXT_VARIATION_PHONETIC



来源:https://stackoverflow.com/questions/6370193/edittext-input-type-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!