0

Before I decided to make this question I've searched the answer here but didn't find. Sorry for my bad inglish but it isn't my native language.

Here's my problem:

I've made an LWUIT 1.5 app generated from the Resource editor into Netbeans, and I want to customize the VirtualKeyboard with my own buttons and then bind them to a TextField but I dont't know WHERE to put the code. I've tried putting it into the BeforeShow my Form "MyForm", or in PostShow like this:

protected void beforeMyForm(Form f) {
   // If the resource file changes the names of components this call will break notifying you that you should fix the code
super.beforeMyForm(f);

VirtualKeyboard vkb = new VirtualKeyboard();

//I declared the new input
String[][] CALC_NUM = new String[][]{
        {"1", "3", "5",},
        {"7", "9", "0",},
        {".","$OK$"}
};
//Added the new input mode
vkb.addInputMode("137_C", CALC_NUM);
vkb.setInputModeOrder(new String[]{"137_C"});

//Bind the vkb to my TextField
VirtualKeyboard.bindVirtualKeyboard(findTfCalc(Display.getInstance().getCurrent()), vkb);

}

In beforeShow theres a NullPointerException and in postShow nothing happens.

In the Properties of the TextField the constraint is Numeric. I know there's a bug with Numeric and Password constraint but I've tried giving the ANY constraint to the TextField, but its not working.

Could someone give me a hand with it?. It would be the same way in Codenameone? Many thanks.

1 Answers1

1

You are using Display.getInstance().getCurrent() instead of using the f, in the before show method the new form isn't yet the current form.

http://codenameone.blogspot.com/2010/06/pimp-virtualkeyboard-by-chen-fishbein.html

Shai Almog
  • 51,749
  • 5
  • 35
  • 65
  • Many thanks. You're right about my error. I had read the article by Chen for some time, very good examples. So I made the correction in beforeShow, but vkb doesn't show any of my own buttons. Even I've tried in Codenameone but it's the same. Anyway, many thanks Shai, Codenameone is a great tool for us. – JEPeralta Aug 21 '12 at 13:55
  • Are you using J2ME? This will only work on a J2ME device, with other platforms we use the native VKB. – Shai Almog Aug 21 '12 at 18:36
  • yes I've realized that isn't a good idea thinking only in the j2me features. I'll implement a global solution for my project. Thanks again. – JEPeralta Aug 22 '12 at 02:19