问题
I have tested many ways to give the numeric and password constraint in the TextField. But its not working, See the below code.
textField.setConstraint(TextField.NUMERIC | TextField.PASSWORD);
textField.setInputModeOrder(new String[]{"123"});
Above code should work on the non touch mobiles. But its not working on the touch mobiles. So i have set the input mode value for VKB
and bind that TextField
with VKB
, see this code.
TextField txt = new TextField();
txt.setConstraint(TextField.NUMERIC |TextField.PASSWORD);
txt.setInputModeOrder(new String[]{"123"});
VirtualKeyboard vkb = new VirtualKeyboard();
vkb.setInputModeOrder(new String[]{VirtualKeyboard.NUMBERS_MODE});
VirtualKeyboard.bindVirtualKeyboard(txt, vkb);
VirtualKeyboard.NUMBERS_MODE
not working when I use above code. VKB
showing as usual format. That means AlphaNumeric
format. Why its showing like this?
回答1:
This is a bug in LWUIT, thanks for bringing it to our attention I'll try to commit a fix for it in the next couple of weeks. It would be sooner but we need to fly to JavaOne soon.
If you want to try the fix locally just update this method in VirtualKeyboard.java:
public void setInputType(int inputType) {
if((inputType & TextArea.NUMERIC) == TextArea.NUMERIC ||
(inputType & TextArea.PHONENUMBER) == TextArea.PHONENUMBER) {
setInputModeOrder(new String []{NUMBERS_MODE});
return;
}
if((inputType & TextArea.DECIMAL) == TextArea.NUMERIC) {
setInputModeOrder(new String []{NUMBERS_SYMBOLS_MODE});
return;
}
setInputModeOrder(defaultInputModeOrder);
}
来源:https://stackoverflow.com/questions/7579142/why-numeric-constraint-didnt-work-on-virtual-keyboard-in-lwuit