开发者

How to create EditField Which accept only text in Blackberry?

开发者 https://www.devze.com 2022-12-08 16:52 出处:网络
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.Y

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.


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.


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));
    }
});
0

精彩评论

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