LWUIT TextArea 无法捕获触摸事件
我用 TextArea
和 CheckBox
制作了一个 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 TextArea
as the lead component of the Container
but it doesn't works because Container
doesn't have an addActionListener
method.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我正确理解这个问题,您将尝试创建一个由多个不同组件组装而成的复合组件,以充当单个组件。在 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.)
最好为
getTextArea()
方法派生
TextArea
类。然后在此类中实现pointerReleased方法:对以正常方式执行的操作进行编码。It is better that you
derive
theTextArea
class for thegetTextArea()
method. Then in this class implement thepointerReleased
method : code the action performed in the normal way in it.