Dev
Dev

Reputation: 199

How to custom Edittext listener

How can I use the edittext listener to prevent the user from entering special characters (&%[email protected]) and also prevent the user from entering numbers, finally allow user to enter only letters (A B C ...)

Upvotes: 0

Views: 416

Answers (2)

user658042
user658042

Reputation:

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.

Upvotes: 1

Dimitris Makris
Dimitris Makris

Reputation: 5183

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.

Upvotes: 0

Related Questions