LWUIT 文本区域问题

发布于 2024-12-03 20:22:32 字数 130 浏览 0 评论 0原文

有没有办法在 textArea 中写入而不进入 LCDUI 窗口? 我想在 LWUIT 应用程序中编辑我的 textArea 但每次我尝试执行此操作时,应用程序都会将我发送到 LCDUI 窗口。

Is there any way to write in a textArea without going to a LCDUI window?
I want to edit my textArea in my LWUIT app but everytime I try to do this, the app send me to a LCDUI window.

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

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

发布评论

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

评论(1

得不到的就毁灭 2024-12-10 20:22:32

要禁用 LWUIT 编辑控件触发器,您可以使用以下代码。

textArea.setNativeTextboxTrigger(false);

需要在LWUIT TextArea源代码中实现以下代码

static final String CLIENT_PROPERTY_FIRE_ACTION_TIMES = "FIRE-ACTION-TIMES";
static final String CLIENT_PROPERTY_DEAFULT_TEXT = "DEFAULT-TEXT";  


public void setNativeTextboxTrigger(boolean enable) {
        registerNativeTextboxTriggerEvent = enable;

         static final String CLIENT_PROPERTY_FIRE_ACTION_TIMES = "FIRE-ACTION-TIMES";
            static final String CLIENT_PROPERTY_DEAFULT_TEXT = "DEFAULT-TEXT";          
        try {
            if( registerNativeTextboxTriggerEvent ) {
                String text = null != ( text = getText() ) ? text : "";  
                this.putClientProperty(CLIENT_PROPERTY_DEAFULT_TEXT, text);
                this.putClientProperty(CLIENT_PROPERTY_FIRE_ACTION_TIMES, String.valueOf(0));
                final UIManager m = UIManager.getInstance();
                setNativeCommandsText(m.localize("ok", "OK"), m.localize("cancel", "Cancel"));
                this.addActionListener(nativeTriggerListener = getNativeTriggerActionListener());
            } else {
                this.putClientProperty(CLIENT_PROPERTY_DEAFULT_TEXT, null);
                this.putClientProperty(CLIENT_PROPERTY_FIRE_ACTION_TIMES, null);
                setNativeCommandsText(null, null);
                if( null != nativeTriggerListener ) {
                    this.removeActionListener(nativeTriggerListener);
                    nativeTriggerListener = null;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }




       ActionListener getNativeTriggerActionListener() {
        return new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                if( evt.getSource() instanceof TextArea ) {
                    final TextArea tar = (TextArea)evt.getSource();
                    final String textEntered = tar.getText().trim();
                    final String defaultText = (String)tar.getClientProperty(CLIENT_PROPERTY_DEAFULT_TEXT);
                    int fireActionTimes = Integer.parseInt((String)tar.getClientProperty(CLIENT_PROPERTY_FIRE_ACTION_TIMES));
                    ++fireActionTimes;
                    int value = fireActionTimes % 2;

                    if( 0 == value ) {
                        fireActionTimes = 0;
                        if( textEntered.equals("") || textEntered.toUpperCase().equals(defaultText.toUpperCase())) {
                            tar.setText(defaultText);
                        }
                        triggeredNativeToLwuit(tar);
                    } else
                    //Switching to native edit screen
                    if( 0 < value ) {
                        if( textEntered.toUpperCase().equals(defaultText.toUpperCase()) ) {
                            tar.setText("");
                        }
                        triggeredLwuitToNative(tar);
                    }                   
                }
            }
        };
    }

To disable the LWUIT edit control trigger you can use the following code.

textArea.setNativeTextboxTrigger(false);

You need to implement the following code in the LWUIT TextArea source code

static final String CLIENT_PROPERTY_FIRE_ACTION_TIMES = "FIRE-ACTION-TIMES";
static final String CLIENT_PROPERTY_DEAFULT_TEXT = "DEFAULT-TEXT";  


public void setNativeTextboxTrigger(boolean enable) {
        registerNativeTextboxTriggerEvent = enable;

         static final String CLIENT_PROPERTY_FIRE_ACTION_TIMES = "FIRE-ACTION-TIMES";
            static final String CLIENT_PROPERTY_DEAFULT_TEXT = "DEFAULT-TEXT";          
        try {
            if( registerNativeTextboxTriggerEvent ) {
                String text = null != ( text = getText() ) ? text : "";  
                this.putClientProperty(CLIENT_PROPERTY_DEAFULT_TEXT, text);
                this.putClientProperty(CLIENT_PROPERTY_FIRE_ACTION_TIMES, String.valueOf(0));
                final UIManager m = UIManager.getInstance();
                setNativeCommandsText(m.localize("ok", "OK"), m.localize("cancel", "Cancel"));
                this.addActionListener(nativeTriggerListener = getNativeTriggerActionListener());
            } else {
                this.putClientProperty(CLIENT_PROPERTY_DEAFULT_TEXT, null);
                this.putClientProperty(CLIENT_PROPERTY_FIRE_ACTION_TIMES, null);
                setNativeCommandsText(null, null);
                if( null != nativeTriggerListener ) {
                    this.removeActionListener(nativeTriggerListener);
                    nativeTriggerListener = null;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }




       ActionListener getNativeTriggerActionListener() {
        return new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                if( evt.getSource() instanceof TextArea ) {
                    final TextArea tar = (TextArea)evt.getSource();
                    final String textEntered = tar.getText().trim();
                    final String defaultText = (String)tar.getClientProperty(CLIENT_PROPERTY_DEAFULT_TEXT);
                    int fireActionTimes = Integer.parseInt((String)tar.getClientProperty(CLIENT_PROPERTY_FIRE_ACTION_TIMES));
                    ++fireActionTimes;
                    int value = fireActionTimes % 2;

                    if( 0 == value ) {
                        fireActionTimes = 0;
                        if( textEntered.equals("") || textEntered.toUpperCase().equals(defaultText.toUpperCase())) {
                            tar.setText(defaultText);
                        }
                        triggeredNativeToLwuit(tar);
                    } else
                    //Switching to native edit screen
                    if( 0 < value ) {
                        if( textEntered.toUpperCase().equals(defaultText.toUpperCase()) ) {
                            tar.setText("");
                        }
                        triggeredLwuitToNative(tar);
                    }                   
                }
            }
        };
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文