Codenameone html按钮代码名1的句柄事件

Codenameone html按钮代码名1的句柄事件,codenameone,Codenameone,在FormI中嵌入了WebBrowser组件,其中包含大量html内容,主要是用于丰富ui的表格、按钮。单击html按钮是否可以处理事件?当然可以,请查看厨房水槽演示以获取示例 通常,只需导航到事件上的URL,并实现自己的BrowserNavigationCallback来处理对该特定URL的导航 这是厨房水槽演示中的代码,请注意setBrowserNavigationCallback块: final WebBrowser wb = new WebBrowser(); if(wb

在FormI中嵌入了WebBrowser组件,其中包含大量html内容,主要是用于丰富ui的表格、按钮。单击html按钮是否可以处理事件?

当然可以,请查看厨房水槽演示以获取示例

通常,只需导航到事件上的URL,并实现自己的BrowserNavigationCallback来处理对该特定URL的导航

这是厨房水槽演示中的代码,请注意setBrowserNavigationCallback块:

    final WebBrowser wb = new WebBrowser();
    if(wb.getInternal() instanceof BrowserComponent) {
        Button btn = new Button("Add");
        final TextArea content = new TextArea();
        Container north = new Container(new BorderLayout());
        north.addComponent(BorderLayout.CENTER, content);
        north.addComponent(BorderLayout.EAST, btn);
        cnt.addComponent(BorderLayout.NORTH, north);
        content.setHint("Add to web document");
        btn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                ((BrowserComponent)wb.getInternal()).execute("fnc('" + content.getText() + "');");
            }
        });
        ((BrowserComponent)wb.getInternal()).setBrowserNavigationCallback(new BrowserNavigationCallback() {
            public boolean shouldNavigate(String url) {
                if(url.startsWith("http://sayhello")) {
                    // warning!!! This is not on the EDT and this method MUST return immediately!
                    Display.getInstance().callSerially(new Runnable() {
                        public void run() {
                            ((BrowserComponent)wb.getInternal()).execute("fnc('this was written by Java code!')");
                        }
                    });
                    return false;
                }
                return true;
            }
        });
    }