Blackberry RichTextField验证

时间:2011-03-21 09:43:38

标签: blackberry

我创建了一个RichTextField,我希望它只允许整数值。我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:3)

您可以尝试这样的事情:

public class MyRichTextField extends RichTextField {

    public MyRichTextField() {
        super();
    }

    public void setText(String text) {
        try {
            int x = Integer.parseInt(text);
            super.setText("" + x);
        } catch (NumberFormatException e) {
            // the text is not a number
            super.setText("");
        }
    }
}