动作监听器不触发

Action listeners not firing

我用 codenameone 开发了一年多了,我以前从未 运行 遇到过这个问题,我觉得我失去了理智。我刚刚重新设计了我正在开发的应用程序的一部分,现在 ActionListener 没有启动。我将它们附加到代码中的 ButtonSpanButton

        ActionListener goToDoc = new ActionListener() {
            String mDocId = docId;

            @Override
            public void actionPerformed(ActionEvent evt) {
                mStateMachine.currentExpertId = mDocId;
                mStateMachine.showForm("DoctorDetails", null);
            }
        };
        name.addActionListener(goToDoc);
        Util.downloadImageToStorage(mStateMachine.URL_PREFIX+"images/doctors/"+(String)value.get("doc_pic"), 
                "doc_post_pic_"+(String)value.get("doc_id")+".png", new Callback<Image>() {
            @Override
            public void onSucess(Image img) {
                pic.setIcon(img.scaledWidth(mStateMachine.getProportionalWidth(.23)));
                StateMachine.applyGreenBorder(pic);
                pic.addActionListener(goToDoc);
                pic.getParent().revalidate();
            }

            @Override
            public void onError(Object sender, Throwable err, int errorCode, String errorMessage) {
                System.out.println("Unable to download expert profile picture");
            }
        });

当我调试代码时,组件确实显示 ActionListener 已附加,但是 actionPerformed 方法永远不会到达,无论我点击按钮多少次。我在模拟器和 Android 设备上都遇到过这个问题。我还没有测试 iPhone.

您是否将父级设置为主要组件或可聚焦组件?

点击事件未触发的原因是组件未启用,可能是 BUI 生成器中的错误。选中 GUI Builder 中的 'Enabled' 和 'Focusable' 复选框后,每次我返回该表单时都看到它们未被选中,我只是在中使用了 component.setFocusable(true)component.setEnabled(true)代码,之后它运行良好。