Codenameone (大多数?)组件未调用longPointerPress()

Codenameone (大多数?)组件未调用longPointerPress(),codenameone,Codenameone,我注意到,longPointerPress不是用于标签派生的 因此,当调用longPointerPress()时,我创建了一些代码来进一步研究,并惊讶地发现: Label派生项确实接收指针事件-但是没有longPointerPress 按钮派生项确实接收指针事件,而longPointerPress只起作用 TextField派生类确实会接收指针事件,除非进行编辑,否则它们会吃掉所有指针事件 我想要实现的是能够在容器中包含各种组件,并且仍然能够在任何情况下获得longPointerPress事

我注意到,
longPointerPress
不是用于标签派生的

因此,当调用
longPointerPress()
时,我创建了一些代码来进一步研究,并惊讶地发现:

  • Label
    派生项确实接收指针事件-但是没有
    longPointerPress
  • 按钮
    派生项确实接收指针事件,而
    longPointerPress
    只起作用
  • TextField
    派生类确实会接收指针事件,除非进行编辑,否则它们会吃掉所有指针事件
我想要实现的是能够在
容器中包含各种组件
,并且仍然能够在任何情况下获得
longPointerPress
事件的通知

我怎样才能做到这一点

下面是代码-长按所有组件并观察控制台:

public class FormLongPointerPress extends Form {
    @SuppressWarnings("unchecked")
    private interface With<T> {
        void act(T ... aTs);
    }

    public FormLongPointerPress() {
        super("FormLongPointerPress");
        setScrollableY(true);
        setLayout(BoxLayout.y());
        With<Component> with = (aComponents) -> {
            Container container = FlowLayout.encloseCenter(aComponents);
            container.addPointerPressedListener((aActionEvent) -> Log.p("container.pointerPressed(" + aActionEvent.getX() + ", " + aActionEvent.getY() + ")"));
            container.addPointerReleasedListener((aActionEvent) -> Log.p("container.pointerReleased(" + aActionEvent.getX() + ", " + aActionEvent.getY() + ")"));
            container.addLongPressListener((aActionEvent) -> Log.p("container.longPress(" + aActionEvent.getX() + ", " + aActionEvent.getY() + ")"));
            for (Component component: aComponents) {
                component.addPointerPressedListener((aActionEvent) -> Log.p("component.pointerPressed(" + aActionEvent.getX() + ", " + aActionEvent.getY() + ")"));
                component.addPointerReleasedListener((aActionEvent) -> Log.p("component.pointerReleased(" + aActionEvent.getX() + ", " + aActionEvent.getY() + ")"));
                component.addLongPressListener((aActionEvent) -> Log.p("component.longPress(" + aActionEvent.getX() + ", " + aActionEvent.getY() + ")"));
            }
            getContentPane().add(container);
        };
        with.act();
        with.act(new Label("A Label"));
        with.act(new Button("A Button"));
        with.act(new TextField("A TextField"));
    }
}
公共类FormLongPointerPress扩展表单{
@抑制警告(“未选中”)
专用接口{
无效行为(T…aTs);
}
公共表单LongPointerPress(){
超级(“FormLongPointerPress”);
setScrollableY(真);
setLayout(BoxLayout.y());
With With=(a组件)->{
容器容器=FlowLayout.encloseCenter(组件);
container.addPointerPressedListener((aaActionEvent)->Log.p(“container.pointerPressed(“+aaActionEvent.getX()+”,“+aaActionEvent.getY()+”));
container.addPointerReleasedListener((aaActionEvent)->Log.p(“container.pointerReleased(“+aaActionEvent.getX()+”,“+aaActionEvent.getY()+”));
container.addLongPressListener((aaActionEvent)->Log.p(“container.longPress(“+aaActionEvent.getX()+”,“+aaActionEvent.getY()+”));
用于(组件:A组件){
component.addPointerPressedListener((aaActionEvent)->Log.p(“component.pointerPressed(“+aaActionEvent.getX()+”,“+aaActionEvent.getY()+”));
component.addPointerReleasedListener((aaActionEvent)->Log.p(“component.pointerReleased(“+aaActionEvent.getX()+”,“+aaActionEvent.getY()+”));
addLongPressListener((aaActionEvent)->Log.p(“component.longPress(“+aaActionEvent.getX()+”,“+aaActionEvent.getY()+”)));
}
getContentPane().add(容器);
};
with.act();
使用.act(新标签(“A标签”));
使用.act(新按钮(“A按钮”));
with.act(新文本字段(“文本字段”));
}
}

我编辑了文本。我的观察有一部分是错误的,我使用的是Shai建议的方法:尝试
setFocusable(true)
我尝试了
setFocusable(true)
,它适用于
Label
衍生产品,但有不同样式的副作用。也许将longPressListener添加到
表单
将是一种有效的方式,可以在没有太多副作用的情况下获得长时间新闻的通知。有没有一个很好的理由,为什么长按不处理非聚焦组件?我编辑了文本。我的观察有一部分是错误的,我使用的是Shai建议的方法:尝试
setFocusable(true)
我尝试了
setFocusable(true)
,它适用于
Label
衍生产品,但有不同样式的副作用。也许将longPressListener添加到
表单
将是一种有效的方式,可以在没有太多副作用的情况下获得长时间新闻的通知。对于不可聚焦的组件,是否有很好的理由不处理长按?