开发者

How to custom Edittext listener

How ca开发者_如何学运维n I use the edittext listener to prevent the user from entering special characters (&%+?@...etc) and also prevent the user from entering numbers, finally allow user to enter only letters (A B C ...)


Check out EditText.setFilters(). This allows you to specify one or more instances of InputFilter for an EditText. These filter certain characters from the input, as the name suggest. There are a lot of prebuild ones (see "know subclasses" at the top of the class documentation), but you may also implement your own by extending the InputFilter class.


You can use add TextWatcher (link: http://developer.android.com/reference/android/text/TextWatcher.html) to your EditText (link: http://developer.android.com/reference/android/widget/TextView.html#addTextChangedListener%28android.text.TextWatcher%29) and implement the three provided methods in order to control the input from the user and perform any operation you want.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜