Why numeric constraint didn't work on Virtual keyboard in LWUIT?

我只是一个虾纸丫 提交于 2019-12-20 04:27:14

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!