【发布时间】:2012-07-31 10:00:20
【问题描述】:
在我的应用程序中,我有一个带有 BasicEditField.FILTER_NUMERIC 的自定义文本框。当用户在字段中输入值时,应将逗号添加到货币格式中。
EX:1,234,567,8.... 像这样。
在我的代码中我尝试过这样。
protected boolean keyUp(int keycode, int time) {
String entireText = getText();
if (!entireText.equals(new String(""))) {
double val = Double.parseDouble(entireText);
String txt = Utile.formatNumber(val, 3, ",");// this will give the //comma separation format
setText(txt);// set the value in the text box
}
return super.keyUp(keycode, time);
}
它将给出正确的数字格式...当我在文本框中设置值时,它将通过IllegalArgumentException。我知道BasicEditField.FILTER_NUMERIC 不会允许像逗号(,)这样的字符..
我怎样才能做到这一点?
【问题讨论】:
-
您需要制作自己的过滤器扩展 TextFielter,blackberry.com/developers/docs/6.0.0api/net/rim/device/api/ui/…。稍后需要将该过滤器设置为 BasicEditField 实例。
-
BasicEditField.FILTER_NUMERIC 已连接到您 BlackBerry 的区域设置。一些语言环境使用不同的方法来分隔句点。
标签: blackberry blackberry-eclipse-plugin blackberry-jde