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
ZevsVU
Posts: 20
Registered: ‎05-17-2012
My Device: have no device
My Carrier: KievStar
Accepted Solution

Two buttons

I need make two buttons.

-first button at the left side of the display

-second button at the right side of the display

 

i try make like this but it dosn't work(

 

HorizontalFieldManager titleHFM = new HorizontalFieldManager(HorizontalFieldManager.FIELD_HCENTER);
HorizontalFieldManager leftHFM = new HorizontalFieldManager(HorizontalFieldManager.FIELD_LEFT);
leftHFM.add(new ButtonField("Left"));
HorizontalFieldManager rightHFM = new HorizontalFieldManager(HorizontalFieldManager.FIELD_RIGHT);
rightHFM.add(new ButtonField("Right",ButtonField.RIGHT));
titleHFM.add(leftHFM);
titleHFM.add(rightHFM);
add(titleHFM);


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

Re: Two buttons

[ Edited ]

Welcome to the forums.

 

I recommend that you use the EvenlySpacedHorizontalFieldmanager or HorizontalButtonFieldSet from here:

http://supportforums.blackberry.com/t5/Java-Development/Implement-advanced-buttons-fields-and-manage...

Please use plain text.
Developer
lakshman9687
Posts: 243
Registered: ‎07-22-2011
My Device: BlackBerry Z10
My Carrier: AirTel

Re: Two buttons

Hi,

 

You can get this by overridng sublayout of the title manager and no need to take seperate manager for each and every button.

 

Try like this,

HorizontalFieldManager titleHFM = new HorizontalFieldManager(HorizontalFieldManager.FIELD_HCENTER)
        {
            protected void sublayout(int maxWidth, int maxHeight)
            {
                setPositionChild(getField(0), 0, 0);
                layoutChild(getField(0), getField(0).getPreferredWidth(),getField(0).getPreferredHeight());
                
                setPositionChild(getField(1), Display.getWidth() - getField(1).getPreferredWidth(), 0);
                layoutChild(getField(1), getField(1).getPreferredWidth(),getField(1).getPreferredHeight());
                
                setExtent(maxWidth, maxHeight);
            }
        };

titleHFM.add(new ButtonField("Left"));
titleHFM.addnew ButtonField("Right");

 

Regards,

Lakshman K

 

----------------------------------------------------------
Feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.

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

Re: Two buttons

I recommend you look at the code supplied in the KB article I previously pointed you at and use that code.  The samples supplied are well written and demonstrate best practice. 

 

Unfortunately the example given above by lakshman9687 has a number of issues.  For example, the last line

setExtent(maxWidth, maxHeight);

will grab the maximum amount of space for the Manager, in fact it only needs enough height for the two buttons. 

Please use plain text.