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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Contributor
Posts: 27
Registered: ‎07-01-2011
My Device: 9800
My Carrier: mobile developer

How to display 2 buttons left and right in line?

[ Edited ]

----------------------------------------------------------------------

- ButtonFieldLeft                           ButtonFieldRigth     - 

-    

-    

-    

----------------------------------------------------------------------

Super Contributor
Posts: 278
Registered: ‎11-04-2010
My Device: 4.5 and above
My Carrier: none

Re: How to display 2 buttons left and right in line?

Hi,

give FIELD_RIGHT and FIELD_LEFT style for button field.

 

ButtonField buttonRight = new ButtonField("ButtonR",FIELD_RIGHT|CONSUME_CLICK);

ButtonField buttonLeft = new ButtonField("ButtonL",FIELD_LEFT|CONSUME_CLICK);

 

Thanks & Regards

               pp

Super Contributor
Posts: 278
Registered: ‎11-04-2010
My Device: 4.5 and above
My Carrier: none

Re: How to display 2 buttons left and right in line?

and put that two buttons in HorizontalFieldManager.
Developer
Posts: 17,025
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: How to display 2 buttons left and right in line?

or use a custom layout manager:
http://supportforums.blackberry.com/t5/Java-Development/Create-a-custom-layout-manager-for-a-screen/...
----------------------------------------------------------
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.
@SimonHain on twitter
Developer
Posts: 467
Registered: ‎07-16-2009
My Device: Z10 LE
My Carrier: Vodafone NL

Re: How to display 2 buttons left and right in line?

If it is the list of such buttons - I would create two VFM and use flags that suggested PP in previous post.

 

If it's one row - HFM and FlowFieldManager will ignore horizontal aligment. And there are two possible solutions - use absolute layout manager (which is availble from 5.0 OS) or implement your own manager with own layout.

Highlighted
Super Contributor
Posts: 278
Registered: ‎11-04-2010
My Device: 4.5 and above
My Carrier: none

Re: How to display 2 buttons left and right in line?

Hi Eugen,
i think FlowFieldManager will create some issue for storm for touch event. we suffered with that issue.
so its better to use HorizontalFieldManager

Thanks & Regards
pp
Super Contributor
Posts: 278
Registered: ‎11-04-2010
My Device: 4.5 and above
My Carrier: none

Re: How to display 2 buttons left and right in line?

Hi,

yes he was right.

 

 If it's one row - HFM and FlowFieldManager will ignore horizontal aligment. And there are two possible solutions - use absolute layout manager (which is availble from 5.0 OS) or implement your own manager with own layout.

 

so here is a custom manager to make the fields align centre and u can change to align right and left

 

public class CenterManager extends Manager {
    private boolean isCenter;
    public CenterManager() {
        super(Manager.USE_ALL_WIDTH);
    }
    public CenterManager(boolean isCenter) {
        super(Manager.USE_ALL_WIDTH);
        this.isCenter = isCenter;
    }
    private int getInitialX(int numberOfFields){
        int x = Display.getWidth();
        for (int i = 0;i < numberOfFields;i++) {
            x -= getField(i).getWidth();
        }
        if(!isCenter){ 
            return x;
        }else{
            return x/2;
        }
    }
    protected void sublayout(int width, int height) { 
        Field field;
        int numberOfFields = getFieldCount();
        int x = getInitialX(numberOfFields);
        int y = 0;
        for (int i = 0;i < numberOfFields;i++) {
            field = getField(i); //get the field
            setPositionChild(field,x,y); //set the position for the field
            layoutChild(field, width, height); //lay out the field
            x += field.getWidth();
        }
        setExtent(getPreferredWidth(), getPreferredHeight());
    }
    public int getPreferredWidth() {
        return Display.getWidth();
    }
    public int getPreferredHeight() {
        if(getFieldCount() == 0)
        {
            return 0;
        }
        return getField(0).getHeight()+5;
    }
}

 CenterManager cm1 = new CenterManager(true);

HorizontalFieldManager buttonManager = new HorizontalFieldManager();

cm1.add(buttonManager );

 

Thanks & Regards

              pp

Contributor
Posts: 27
Registered: ‎07-01-2011
My Device: 9800
My Carrier: mobile developer

Re: How to display 2 buttons left and right in line?

What is CONSUME_CLICK?
Super Contributor
Posts: 278
Registered: ‎11-04-2010
My Device: 4.5 and above
My Carrier: none

Re: How to display 2 buttons left and right in line?

CONSUME_CLICK

public static final long CONSUME_CLICK

Indicates to the button consume the click event. Since: JDE 4.0.0

 

when the user click on the button the specified action to be performed by consuming that event.

 

In JDE, go to help tab, API preferences and you will get all the components and its details.

 

Thanks & Regards

              pp

Super Contributor
Posts: 278
Registered: ‎11-04-2010
My Device: 4.5 and above
My Carrier: none

Re: How to display 2 buttons left and right in line?

Hi,

  check this custom manager --  BFHM here..

http://supportforums.blackberry.com/t5/Java-Development/Wrong-FieldChangeListener-invoked-for-custom...

 

Thanks & Regards

             pp