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
jushlwest
Posts: 27
Registered: ‎07-01-2011
My Device: 9800

How to display 2 buttons left and right in line?

[ Edited ]

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

- ButtonFieldLeft                           ButtonFieldRigth     - 

-    

-    

-    

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

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

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
pp
Posts: 278
Registered: ‎11-04-2010
My Device: 4.5 and above

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

and put that two buttons in HorizontalFieldManager.
Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

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
Eugen
Posts: 467
Registered: ‎07-16-2009
My Device: Z10 LE

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.

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

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
pp
Posts: 278
Registered: ‎11-04-2010
My Device: 4.5 and above

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
jushlwest
Posts: 27
Registered: ‎07-01-2011
My Device: 9800

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

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

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
pp
Posts: 278
Registered: ‎11-04-2010
My Device: 4.5 and above

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