Blackberry Event Handling and Focus Issues

2019-08-19 01:51发布

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.

标签: blackberry
2条回答
疯言疯语
2楼-- · 2019-08-19 02:24

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.

查看更多
太酷不给撩
3楼-- · 2019-08-19 02:26

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.

查看更多
登录 后发表回答