Blackberry Event Handling and Focus Issues

限于喜欢 提交于 2019-12-12 00:31:40

问题


I am having an issue with a small blackberry application where touch events are being processed by 1 of 2 certain fields that has focus.

In my case, I have 2 images, one at the top (first element on the screen) and at the bottom (last element added to the screen. Both are subclasses of the BitmapField. Their purpose is to display a web site when the user taps (clicks with the trackpad/ball).

The issue is when either of these has focus, no matter where the user taps on the screen (i.e. in an EditField, another custom button, or just a part of the background), the BitmapField that has focus consumes the event calls the web browser. This obviously only an issue on the BB Torch simulator, and I building for BB OS 5.0.

I have the BitmapField consuming both navigation clicks and touch events.

Also, any direction on where to get a good (as in not written by RIM) event handling guide for the Blackberry API would be helpful.

UPDATE: I have tried:

    public boolean isFocusable() {
        return false;
    }

But, ideally I would like this to work on devices such as the Curve and Bold.

UPDATE 2: There a couple of LabelFields inside layout managers that can receive focus, but they do not cause this issue, it only happens when the BitmapFields have focus.


回答1:


I'd suggest to create a custom image button field by subclassing from Field. Override paint(Graphics graphics) to draw image and focused border (or background). Then just override navigationClick(int status, int time). The BB UI framework will call that method when user clicks your field on a touch screen. As well it'll work for a non-touch screen devices. As a great benefit - you will not need to bother yourself with TouchEvents at all.




回答2:


Make sure that on the touchEvent() you are checking the location of the touch. If it is outside of your BitmapField's extent, you should be returning super.touchEvent(message). Regardless of where the touch is, when a field has focus it is sent to it first to determine if it should be handling it at all.



来源:https://stackoverflow.com/questions/6349522/blackberry-event-handling-and-focus-issues

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!