How to make EditField which accept only alphabets and it should not accept any Numeric,any special character in blackberry.ie) that editfield should accept only alphabetic character.
A:
You could create your own class (i.e AlphaEditField) and have it extend EditField. Then override the keyDown function to do what you want, something like so:
protected boolean keyDown(int keycode, int time) {
char ch = net.rim.device.api.ui.Keypad.map(keycode);
if(Character.isUpperCase(ch) || Character.isLowerCase(ch)) {
return super.keyDown(keycode, time);
}
return false;
}
The upper and lower case functions will return false for any character that can't be defined in case, aka...anything not in the alphabet.
Fostah
2009-10-19 12:24:15
A:
I would define a TextFilter like so:
myEditField.setFilter(new TextFilter(){
public char convert(char character, int status) {
return character; // because you're trying to disallow characters, not convert them.
}
public boolean validate(char character) {
return (Character.isUpperCase(character) || Character.isLowerCase(character));
}
});
Jeff
2010-01-28 22:57:37