编辑字段时如何打开与文本字段关联的虚拟键盘?

发布于 2024-12-11 07:09:22 字数 1374 浏览 0 评论 0原文

我在 startApp() 中初始化了 VKBImplementationFactory

public void startApp() {
        VKBImplementationFactory.init();
        Display.init(this);
        new MenuPrincipalForm(this).show();
    }

我还在表单中创建了一个 VirtualKeyboard :

...
private VirtualKeyboard vkNombre = new VirtualKeyboard();
...
vkNombre.setInputModeOrder(new String[]{VirtualKeyboard.NUMBERS_SYMBOLS_MODE});

并且我将此 VirtualKeyboard 绑定到了一个 TextField :

cintxt=new TextField();
VirtualKeyboard.bindVirtualKeyboard(cintxt, vkNombre);

我注册了 dataChangeListener > 到此 TextField :

public class ModifierFicheClient extends Form implements ActionListener, DataChangedListener 
{
  ...
  cintxt.addDataChangeListener(this);
  ...
}

dataChanged(int type, int index) 方法中,我想打开 vkNombre VirtualKeyBoard。我知道,当单击 TextField 时,会自动显示 VirtualKeyboard 。但有一种情况是,当通过手机移动滚动软按钮导航到 TextField 时,我可以导航到 TextField 而无需单击它,并且我可以输入任何字母!那么在手机上打字时如何调用VirtualKeyboard呢?

注意:我在 dataChanged(int type, int index) 方法中编写了 System.out.println("zzzz"); ,并且输出写入两行“zzzz”我输入一个字符!那么为什么当我只输入一个字母时,dataChanged 方法会被调用两次

I initialized the VKBImplementationFactory in startApp() :

public void startApp() {
        VKBImplementationFactory.init();
        Display.init(this);
        new MenuPrincipalForm(this).show();
    }

I created also a VirtualKeyboard in a Form :

...
private VirtualKeyboard vkNombre = new VirtualKeyboard();
...
vkNombre.setInputModeOrder(new String[]{VirtualKeyboard.NUMBERS_SYMBOLS_MODE});

And I bound this VirtualKeyboard to a TextField :

cintxt=new TextField();
VirtualKeyboard.bindVirtualKeyboard(cintxt, vkNombre);

I registered dataChangeListener to this TextField :

public class ModifierFicheClient extends Form implements ActionListener, DataChangedListener 
{
  ...
  cintxt.addDataChangeListener(this);
  ...
}

In the dataChanged(int type, int index) method I want to open the vkNombre VirtualKeyBoard. I know that when clicking the TextField then the VirtualKeyboard is shown automatically. But there is a case when navigating to the TextField through the phone mobile scroll softbuttons then I can navigate to the TextField without clicking it and I can type any letters ! So how to call the VirtualKeyboard when typing a letter on the phone mobile ?

NB : I wrote System.out.println("zzzz"); in the dataChanged(int type, int index) method and the output writes two lines "zzzz" when I type one character ! So why the dataChanged method is called two times when I type only one letter ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鼻尖触碰 2024-12-18 07:09:22

无需在 startApp() 中使用 VKBImplementationFactory.init();。因为LWUIT会自动检测该手机是否是触摸屏。当您使用 LWUIT 1.5 或之前的版本时,数字约束在 VKB 上不起作用。这是该版本的错误。但它将在 LWUIT 的当前存储库版本< /a>(修订版:1605)。因此,您可以从存储库中签出并使用最新的 LWUIT jar。

更新:

请参阅显示 VKB 的示例代码,同时关注 TextField

TextField textField = new TextField();
final VirtualKeyboard keyboard = new VirtualKeyboard();
textField.addFocusListener(new FocusListener() {

     public void focusGained(Component cmp) 
          keyboard.show();
     }
     public void focusLost(Component cmp) {
          keyboard.dispose();
     }
});
keyboard.setTextField(textField);

No need to use VKBImplementationFactory.init(); in startApp(). Because LWUIT automatically detect whether that mobile is touch screen or not. And numeric constraint not working on VKB when you use LWUIT 1.5 or before versions. It is bug on that versions. But it will be fixed on current repository version of LWUIT (Revision: 1605). So you can checkout from repository and use the latest LWUIT jar.

Update:

See the sample code for showing VKB while focusing on TextField,

TextField textField = new TextField();
final VirtualKeyboard keyboard = new VirtualKeyboard();
textField.addFocusListener(new FocusListener() {

     public void focusGained(Component cmp) 
          keyboard.show();
     }
     public void focusLost(Component cmp) {
          keyboard.dispose();
     }
});
keyboard.setTextField(textField);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文