1
votes

I'm trying to display a virtual keyboard when TextField is focused. When I tested it on an Android phone, its default keyboard is being shown and not the customized one.

    Form testForm = new Form(new BorderLayout());
    TextField txt = new TextField(); 

    String[][] arrOfNumbers = new String[][]{{"1","2","3",}, {"4","5","6",}, {"7","8","9",}, {"0", "00", "$OK$"}};

    VirtualKeyboard virtualKB = new VirtualKeyboard(); 
    virtualKB.addInputMode("NUM_KB", arrOfNumbers);
    virtualKB.setInputModeOrder(new String[]{"NUM_KB"});
    VirtualKeyboard.bindVirtualKeyboard(txt, virtualKB);

    testForm.add(BorderLayout.NORTH, txt);        
    testForm.show();
1

1 Answers

1
votes

The virtual keyboard class is a part of legacy functionality and shouldn't be used. Codename One uses native input, your code will work with the native numeric input by using:

Form testForm = new Form(new BorderLayout());
TextField txt = new TextField(); 
txt.setConstraint(TextField.NUMERIC);

testForm.add(BorderLayout.NORTH, txt);        
testForm.show();