views:

1070

answers:

3

Hi There, 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

+1  A: 

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:

 protected boolean navigationClick(int status, int time) { return true; }
haagmm
+4  A: 

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 explaination 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:

ButtonField myButtonField = 
    new ButtonField( ButtonField.CONSUME_CLICK | ButtonField.NEVER_DIRTY );

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.

Alex W
A: 

I have this same problem, only with a Bitmap field that I have made clickable. have not found a working solution yet.

footose