开发者

EditText Input type Issue

开发者 https://www.devze.com 2023-03-13 04:44 出处:网络
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.

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"开发者_如何学Go is working it accepting means showing numbers in field` only.

Why like that?


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.


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.


Try using TYPE_TEXT_VARIATION_PHONETIC

0

精彩评论

暂无评论...
验证码 换一张
取 消