开发者

Onclick validate edittext if user enters an int with a string

I have in my application an EditText which validates that the user cannot enter a integer when the user clicks a button.

This is done by an if statement 开发者_开发问答on a condition where word is a String:

(word.matches("[0-9]*")

How can I change this if a user enters a word with a string as well.

Thanks


An EditText inherits from a TextView, which has a method called setInputType. This method accepts an int defined as InputType. So you can set the InputType dynamically depending on what you want/the user clicks


To do this kind of filter in EditText, the better way is to specify the android:inputType. This allow you to specify what you expect and also to display the right keyboard. Another option is to use android:digit to specify the autorized characters. If you need numeric, enter

android:digit="0123456789"

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜