黑莓风暴触摸事件
我已将 Blackberry 4.6.0 应用程序移植到 4.7.0 的 Storm 上。 除了我试图控制的触摸事件之外,一切都工作正常。 我在下面的方法中捕获触摸事件,它按预期执行,但问题是 在 touchEvent 中的逻辑执行并返回后,始终显示菜单(通过菜单按钮激活)。 我尝试返回 false、true 和 super.touchEvent(message) 但它仍然出现。
关于如何防止菜单在捕获触摸事件后出现的任何想法?
protected boolean touchEvent(TouchEvent message)
{
if (message.getEvent() == TouchEvent.CLICK)
{
//My code here
}
}
非常感谢您的想法
Ive ported an Blackberry 4.6.0 application over to the storm on 4.7.0.
All is working fine apart from the touch events i'm trying to control.
I trap touch events in the method below which does as its supposed to but the problem is
after my logic in the touchEvent executes and return the Menu (thats activated via menu button) is always displayed.
I've tried returning false, true and super.touchEvent(message) but it still appears.
Any ideas of how I can prevent the Menu from appearing after trapping touch event?
protected boolean touchEvent(TouchEvent message)
{
if (message.getEvent() == TouchEvent.CLICK)
{
//My code here
}
}
Your thoughts are much appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您“单击”屏幕或在 sim 中单击鼠标左键,您将触发上下文菜单,类似于在 4.6 设备上单击轨迹球。
您需要在重载 touchEvent 的字段上执行类似的操作:
If you're "clicking" the screen or left clicking the mouse in the sim you will trigger the context menu, similar to if you clicked the trackball on a 4.6 device.
You will need to do something similar to this on the field you overloaded touchEvent in:
只是为了澄清 haagmm 的答案:
将 TouchEvent.CLICK 发送到您的应用程序后,还将发送 navigationClick 事件。 这是出于兼容性原因,因此即使应用程序尚未明确编写为响应触摸事件,ButtonFields 之类的东西也可以在触摸屏设备上运行。
如果应用程序中的字段未使用 navigationClick 事件(返回 true),则将显示上下文菜单。
如果您在单击按钮字段时看到此行为,则说明默认情况下,ButtonFields 不消耗单击事件。 我发现始终使用以下样式位集构造 ButtonFields 是一种好的做法:
haagmm 的代码是一种解决方案,但更好的想法是复制 TouchEvent.CLICK 处理代码并将其粘贴到 navigationClick 方法中。 这样,像 BlackBerry Tour 这样的轨迹球设备仍然能够使用您的应用程序。
Just to clarify haagmm's answer:
After a TouchEvent.CLICK has been sent to your application, a navigationClick event will also be sent. This is for compatibility reasons, so things like ButtonFields will work on a touchscreen device even if the app hasn't been explicitly written to respond to touchEvents.
If a navigationClick event is not consumed (return true) by a field in your app, the context menu will be displayed.
If you're seeing this behaviour when clicking on a button field, the explanation is that by default, ButtonFields do not consume click events. I have found that is it good practice to always construct ButtonFields with the following style bits set:
haagmm's code is one solution, but a better idea is to copy your TouchEvent.CLICK handling code and also paste it in the navigationClick method. That way, a trackball device like the BlackBerry Tour will still be able to use your application.