If you are using Internet Explorer, please remove blackberry.com from your compatibility view settings.

Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
arindamhit
Posts: 271
Registered: ‎12-24-2010
My Device: BlackBerry 10
My Carrier: Airtel
Accepted Solution

Menu pop up is coming for the long press of the label field

I have a screen where i have a clickable labelfield. For this i am overriding the touchEvent(). Now in the screen i am adding two menus. So when i am touching the labelfield for long, it is showing the menu pop up with those two menu which i don't want. How can i hide this menu pop up??

 

This is happening as i am returning super.touchEvent() for the touch event method(overridden).

Please help.

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Menu pop up is coming for the long press of the label field

I don't think this a good idea.  This is not a method used elsewhere on these phones. 

 

One way the BB gives the option of 'two' menus is to use the menu key for the full menu and the trackpad for the small menu.  I would use two different actions like this.

 

Also, how is this going to work on non touch devices?

 

You do have to return true to the events you do not wish the OS to process, so you should be able to use that to suppress the menu - I think it is generated on UNCLICK, but that is just a guess. 

Please use plain text.
Developer
arindamhit
Posts: 271
Registered: ‎12-24-2010
My Device: BlackBerry 10
My Carrier: Airtel

Re: Menu pop up is coming for the long press of the label field

So this way i am adding the menus:

 

public void makeMenu( Menu menu, int instance )
	{
		this.mMenuList = menu;
		MenuItem viewlog = new MenuItem("Viewlog", 1, 1) {
			public void run() {
				UiApplication.getUiApplication().invokeLater(new Runnable() {
					
					public void run() {
						// TODO Auto-generated method stub
						// My task
					}
				});
			}
		};	
		
		MenuItem clearlog = new MenuItem("Clear Log", 2, 2) {
			public void run() {
				UiApplication.getUiApplication().invokeLater(new Runnable() {
					
					public void run() {
						// TODO Auto-generated method stub
						// My task
					}
				});
			}
		};
	  
		  mMenuList.add( viewlog );
		  mMenuList.add( clearlog ); 
	  super.makeMenu( mMenuList, instance);
	}

 Now for touch screen i am using the navigation Click :

 

if(Touchscreen.isSupported())
		{
			mLfReset = new LabelField(mResources.getString(TERMS_CONDITIONS), Field.FIELD_LEFT|Field.FIELD_VCENTER | Field.FOCUSABLE | ButtonField.CONSUME_CLICK)
			{
				protected boolean navigationClick(int status, int time) 
				{
					//some work
					return true;
				}
			};
		}

  Now when i am pressing long the label field, it is showing the menus which i have added. What is the solution??

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Menu pop up is coming for the long press of the label field

Interesting.  I didn't know that happened.

 

I am not sure that the following is the solution, but I suspect it will help you find code that does what you want.

 

mLfReset = new LabelField("terms", Field.FIELD_LEFT|Field.FIELD_VCENTER | Field.FOCUSABLE) {
		protected boolean navigationClick(int status, int time) {
			System.out.println("navigationClick");
			return true;
		}
	    protected boolean touchEvent(TouchEvent message) {
	        int x = message.getX( 1 );
	        int y = message.getY( 1 );
	        if( x < 0 || y < 0 || x > getExtent().width || y > getExtent().height ) {
	                // Outside the field
	                return false;
	        }
	        System.out.println("Touch: " + Integer.toString(message.getEvent()));
	        if ( message.getEvent() == TouchEvent.GESTURE ) {
	        	TouchGesture gesture = message.getGesture();
	        	System.out.println("Gesture: " + Integer.toString(gesture.getEvent()));
	        	if ( gesture.getEvent() == TouchGesture.HOVER ) {
	        		return true;
	        	}
	        }
	        return super.touchEvent(message);
	    }
	};

 

I would like to make a few comments about your code:

 

1) You do this:

MenuItem viewlog = new MenuItem("Viewlog", 1, 1) {

...

}

every time you got through makeMenu.  This means you create a new MenuItem every time.  I suspect you can possibly get away with creating one and reusing it and that would be more efficient.

 

2) In your MenuItems you do this:

UiApplication.getUiApplication().invokeLater(new Runnable() {

..

};

In fact MenuItems actually run with the Event Thread, so this is redundant. 

 

3) mLfReset = new LabelField(mResources.getString(TERMS_CONDITIONS), Field.FIELD_LEFT|Field.FIELD_VCENTER | Field.FOCUSABLE | ButtonField.CONSUME_CLICK)

You should not use a style that is specific to a Field (in this case ButtonField) in another Field (in this case LabelField).  They are not defined, so results are unpredictable. 

Please use plain text.
Developer
arindamhit
Posts: 271
Registered: ‎12-24-2010
My Device: BlackBerry 10
My Carrier: Airtel

Re: Menu pop up is coming for the long press of the label field

I have changed the adding menu code like this and it is working:

 

public void makeMenu( Menu menu, int instance )
	{
		super.makeMenu( menu, instance);
		
		if(instance == Menu.INSTANCE_DEFAULT)
		{
			 menu.add(new MenuItem("xxx", 1, 1) {
				public void run() {
					
				}
			});	
			
			 menu.add(new MenuItem("yyy", 2, 2) {
				public void run() {
					
				}
			});
		}
	  
	}

 this line has made the difference here:

 

if(instance == Menu.INSTANCE_DEFAULT)
Please use plain text.