08-17-2009 03:31 PM - edited 08-17-2009 03:39 PM
I'm running into the following scenario on some devices: when the use clicks on field and expects an response, instead of properly responding to that click event, the device shows the context menu at the bottom center of the screen.
From what I've read, I can override navigationUnclick and trackwheelUnclick to prevent the menu from showing. I'm doing this as the screen level but reproducing the centered-menu scenario is difficult. Is this the correct approch?
Why does this happen? Is there any way to resolve this?
08-17-2009 06:28 PM - edited 08-17-2009 09:02 PM
You need to override navigationClick, not navigationUnclick or trackwheelUnclick. Code like this should do the trick:
protected boolean navigationClick(int status, int time) {
// only override menu behavior for unmodified click
if ((status & KeypadListener.STATUS_ALT) == 0 &&
(status & KeypadListener.STATUS_SHIFT) == 0)
{
// respond to click here
return true; // suppresses showing of context menu
}
return super.navigationClick(status, time);
}
08-17-2009 06:34 PM
If this occurs on a ButtonField, you should add the style CONSUME_CLICK to the field.
06-22-2010 01:55 PM
Thank you so much for this snippet. It only took me a couple of days** ! thanks again ![]()
06-22-2010 02:07 PM
One question why use the bitwise AND operator.. == 0
If i'm not mistaken, you are comparing every bit of the integer status and the keypadListener.Status_Alt. if at least one bit is not the same it will return a 0.
Why not just simply use the != operator.
I think there is an implicit cast from int -> long
so doing the int != long would eventually yield a long != long
... just wondering..
Thanks.
06-22-2010 02:47 PM
Hopefully this will explain the use of the bitwise operation and == 0
1100 & 0100 will give 0100, which is not equal to 0
1100 & 0001 will give 0000, which is equal to 0
but
1100 != 0100 is true, and
1100 != 0001 is true too
Does that make sense?
06-22-2010 06:21 PM - edited 06-22-2010 06:22 PM
@malbito -- I'm not sure where you see an implicit cast to long. Everything is an int, and the & operator returns an int if both args are int.
Peter has a good explanation of the use of the & operator. I'd just add that your statement "if at least one bit is not the same it will return a 0" is incorrect. Rather, the operator works bit-by-bit -- each bit of the result is the logical and of the corresponding bits of the two arguments. The result will be non-0 if there is at least one bit position at which both arguments have a 1.
07-21-2010 11:59 AM
thanks, it makes sense.