08-29-2012 07:31 AM - edited 08-29-2012 07:49 AM
I want to prevent the popup menu (context menu) from displaying upon touch&hold on touch devices (not SurePress).
Currently, I am overriding the touchEvent() method and consuming it in case of TouchGesture.HOVER.
protected boolean touchEvent(TouchEvent message) {
if ((TouchEvent.GESTURE == message.getEvent()) && (TouchGesture.HOVER == message.getGesture().getEvent())) {
return true;
}
return super.touchEvent(message);
}
It work's but I'd like to know whether there is a better way of doing it for specific field.
Solved! Go to Solution.
08-29-2012 07:45 AM
08-29-2012 07:58 AM
Anand04,
Override makeMenu and do what exactly? I think you also meant Menu.INSTANCE_CONTEXT and not Menu.INSTANCE_DEFAULT.
In any case, this kind of approach involves overriding the MainScreen's makeMenu() method. I prefer something that is more surgical (field specific rather than screen specific).
Thanks for the answer.
08-29-2012 07:59 AM - edited 08-29-2012 08:01 AM
use this code:
protected void makeMenu(Menu menu, int instance) {
if(instance == Menu.INSTANCE_DEFAULT){
// add your menu item here......
}
}
08-29-2012 08:04 AM
08-29-2012 08:09 AM - edited 08-29-2012 08:10 AM
I just want to make sure that there is no way to prevent the popup menu from displaying other than overriding touchEvent() (either for the field or for the screen) and consuming the TouchGesture.Hover gesture.
08-29-2012 08:22 AM
08-30-2012 04:08 AM - edited 08-30-2012 04:28 AM
Alternatively, if one wants to prevent the context menu from showing no matter how it was invoked, then IMHO one of the most easiest solutions would be to override the Screen's makeMenu() method and super.makeMenu() called only in case the instance parameter == Menu.DEFAULT_INSTANCE. This code disables the context menu for all field on the screen.
protected void makeMenu(Menu menu, int instance) {
if (Menu.INSTANCE_DEFAULT == instance) {
super.makeMenu(menu, instance);
}
}
If one want to disable the context menu for some specific field, then the following code can be used.
protected void makeMenu(Menu menu, int instance) {
if ((Menu.INSTANCE_DEFAULT != instance) && (getLeafFieldWithFocus() == someSpecificField)) {
return;
}
super.makeMenu(menu, instance);
}