0

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.

CRUSADER
  • 5,486
  • 3
  • 28
  • 64
Kumar
  • 5,469
  • 20
  • 64
  • 87

2 Answers2

1

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
  • 11,398
  • 10
  • 46
  • 55
1

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
  • 674
  • 5
  • 6