代号一个带有动作侦听器的容器
codename one container with action listener
我正在使用代号 One 开发我的第一个移动应用程序。我正在尝试让容器对正常的点击操作事件做出反应。
我有一个容器(注意这不是 swing 容器,而是一个代号为 one 的容器),它在一个可滚动的方框 Y_axis 布局中包含列表元素。到目前为止,一切都很好。这些元素本身就是容器,其中包含标签、图像和星形滑块。
现在,当用户单击整个元素容器中的任意位置时,我想切换到另一个表单以显示该条目的详细信息。
但是,容器不提供添加动作侦听器。仅仅实现 actionlistener 接口也无济于事。下一个问题是,代号 one 容器也没有 mouselistener,因为移动应用程序没有鼠标可以点击。
那么,我如何识别点击容器?
谢谢并致以最诚挚的问候
创建一个按钮并为其提供 actionListener,然后将其设置为容器的 leadComponent,好处是您不必将其添加到容器中。
Button myBtn = new Button();
myBtn.addActionListener(e -> {
//go to other form here
});
Container myCont = new Container();
myCont.setLeadComponent(myBtn);
在评论中找到了我自己的问题的答案。
按照 Diamond 的说明设置主要组件后,您可以通过设置 setBlockLead(true)
从主要组件事件处理中排除某些组件
以上面的示例为例,我们可以使用以下内容对其进行扩展:
Button leadBtn = new Button();
leadBtn.addActionListener(e -> {
//Handle action of the lead button
});
Button anotherBtn = new Button();
anotherBtn.addActionListener(e -> {
//Handle action of the another button
});
Container myCont = new Container();
myCont.add(leadBtn);
myCont.add(anotherBtn);
myCont.setLeadComponent(leadBtn);
anotherBtn.setBlockedLead(true);
我正在使用代号 One 开发我的第一个移动应用程序。我正在尝试让容器对正常的点击操作事件做出反应。 我有一个容器(注意这不是 swing 容器,而是一个代号为 one 的容器),它在一个可滚动的方框 Y_axis 布局中包含列表元素。到目前为止,一切都很好。这些元素本身就是容器,其中包含标签、图像和星形滑块。
现在,当用户单击整个元素容器中的任意位置时,我想切换到另一个表单以显示该条目的详细信息。 但是,容器不提供添加动作侦听器。仅仅实现 actionlistener 接口也无济于事。下一个问题是,代号 one 容器也没有 mouselistener,因为移动应用程序没有鼠标可以点击。
那么,我如何识别点击容器?
谢谢并致以最诚挚的问候
创建一个按钮并为其提供 actionListener,然后将其设置为容器的 leadComponent,好处是您不必将其添加到容器中。
Button myBtn = new Button();
myBtn.addActionListener(e -> {
//go to other form here
});
Container myCont = new Container();
myCont.setLeadComponent(myBtn);
在评论中找到了我自己的问题的答案。
按照 Diamond 的说明设置主要组件后,您可以通过设置 setBlockLead(true)
以上面的示例为例,我们可以使用以下内容对其进行扩展:
Button leadBtn = new Button();
leadBtn.addActionListener(e -> {
//Handle action of the lead button
});
Button anotherBtn = new Button();
anotherBtn.addActionListener(e -> {
//Handle action of the another button
});
Container myCont = new Container();
myCont.add(leadBtn);
myCont.add(anotherBtn);
myCont.setLeadComponent(leadBtn);
anotherBtn.setBlockedLead(true);