LWUIT TextArea 无法捕获触摸事件

发布于 2025-01-03 19:10:38 字数 633 浏览 0 评论 0原文

我用 TextAreaCheckBox 制作了一个 Container 复合体。在我的应用程序中,我创建了很多这样的“Containers”,并向其中的每个 TextArea 添加一个 ActionListener (由类实现) 。像这样的事情:

for(int i = 0 ; i<20;i++){
 MyContainer c = new MyContainer();
 TextArea t = c.getTextArea();
 t.addActionListener(this);
}

我希望 TextArea 捕获该事件,如果按下该事件,则选中或取消选中 CheckBox 。它在非触摸设备和模拟器中工作正常,但在触摸设备或模拟器中,TextArea 无法捕获事件。我尝试将 TextArea 作为 Container 的主要组件,但它不起作用,因为 Container 没有 addActionListener 方法。

I have made a Container compound by a TextArea and a CheckBox. In my app, I create so many of this "Containers" and add to each TextArea inside of them an ActionListener (implemented by the class). Something like this:

for(int i = 0 ; i<20;i++){
 MyContainer c = new MyContainer();
 TextArea t = c.getTextArea();
 t.addActionListener(this);
}

I want the TextArea to catch the event and if it is pressed put the CheckBox checked or unchecked. It works fine in non-touch devices and simulators but in the touch devices or emulators, the TextArea doesn't catch the event. I tried to put the TextAreaas the lead component of the Container but it doesn't works because Container doesn't have an addActionListener method.

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

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

发布评论

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

评论(2

み格子的夏天 2025-01-10 19:10:38

如果我正确理解这个问题,您将尝试创建一个由多个不同组件组装而成的复合组件,以充当单个组件。在 LWUIT/Codename One 中,这称为 Lead 组件,所附文章主要是关于资源编辑器的,但这些概念也适用于手动编码。
只需将“复选框”设置为您的引导,一切就应该可以正常工作。

您可以通过派生和覆盖来手动编码,但是您会遇到一些小的边缘情况,例如样式状态的更改(聚焦/按下状态等)

If I understand the question correctly you are trying to create a compound component assembled from multiple different components to act like a single component. In LWUIT/Codename One this is called a Lead Component, the attached post is mostly about the resource editor but the concepts apply to manual coding as well.
Just set the "checkbox" as your lead and everything should work.

You can code this manually by deriving and overriding but you will there are small edge cases like the change of style states (focused/pressed state etc.)

迎风吟唱 2025-01-10 19:10:38

最好为 getTextArea() 方法派生 TextArea 类。然后在此类中实现pointerReleased方法:对以正常方式执行的操作进行编码。

It is better that you derive the TextArea class for the getTextArea() method. Then in this class implement the pointerReleased method : code the action performed in the normal way in it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文