Discover latest Indian Blogs Visit BlogAdda.com to discover Indian blogs

Monday 30 December 2019

Android EditText : setFilters Example : Numeric Text field Patterns and Length Restriction.

Sometimes requirement comes in a way when one needs to restrict characters to be entered in Edit Text. Scenario can be “username should be greater than 6 characters”, “accepts only decimal number with 2 digits after fraction”, etc.
In this regard, EditText’ setFilters works at its best. EditText’s setFilters method can be used while playing with length of characters to be entered or entering data in particular pattern in EditText. To freeze such requirement with quickest solution, I have written Custom EditText Locker. One can use this class file along with two lines of code in Main activity to suffice the purpose. If needed more patterns of accepting data in EditText can be added to same class file to make it more generic. For example to make custom locker I have added two EditTexts one which accepts any character with limit of 4 and another EditText which accepts decimal number with only two digits after fraction.
Read More About Android EditText.