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
Contributor
atif_imran
Posts: 13
Registered: ‎10-04-2012
My Device: BlackBerry 9930
My Carrier: RIM
Accepted Solution

How to avoid HorizontalFieldManager from being clicked

[ Edited ]

I have added a footer image on my setStatus() and over that image I have used a HorizontalFieldManager that contains two buttons.

 

When I click on the footer image the button is clicked I don't understand why. Please help.

 

Here's the code:

 

//In my main screen

setStatus(footerStatus(getButtonBar()));

...

public Field getButtonBar(){
HorizontalFieldManager hfm1 = new HorizontalFieldManager(USE_ALL_WIDTH|Manager.NO_HORIZONTAL_SCROLL|Manager.NO_HORIZONTAL_SCROLLBAR);

backButton.setMargin(DeviceManager.getBackButtonTopMargin(),0,0,DeviceManager.getBackButtonLeftMargin());
		nextButton.setMargin(DeviceManager.getNextButtonTopMargin(),0,0,DeviceManager.getNextButtonLeftMargin(nextBtnLeftMargin));
    hfm1.add(backButton);
    hfm1.add(nextButton);
    return hfm1;
}

...

public Field footerStatus(Field button) {
Bitmap bm = Bitmap.getBitmapResource("img/footer.PNG");

HorizontalFieldManager hfm0 = new HorizontalFieldManager(USE_ALL_WIDTH|Manager.NO_HORIZONTAL_SCROLL|Manager.NO_HORIZONTAL_SCROLLBAR);

Background bg = BackgroundFactory.createBitmapBackground(bm, Background.POSITION_X_LEFT, Background.POSITION_Y_BOTTOM, Background.REPEAT_SCALE_TO_FIT);
    hfm0.setBackground(bg);
    hfm0.add(button);
    return hfm0;
}

 

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

Re: How to avoid HorizontalFieldManager from being clicked

When you touch a place on the screen, the system will look for a focusable Field in the area that you touched and direct your click at that.  If it can't find this, it will direct the click to the Field in focus.  If you want to ignore these, you have to supress clicks when the initiating locaiton is outside your Field.  Here is some sample code:

 

               

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;

}

Please use plain text.
Contributor
atif_imran
Posts: 13
Registered: ‎10-04-2012
My Device: BlackBerry 9930
My Carrier: RIM

Re: How to avoid HorizontalFieldManager from being clicked

Thanks Peter!

I simply did what you said. Overridden the touchEventmethod and within it called the method navigationClick on the following check(if it was false):

if( x < 0 || y < 0 || x > getExtent().width || y > getExtent().height ) 

 

It worked and I learnt something good. :Genius:You're just a saviour :smileywink:

 

Please use plain text.