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
Posts: 660
Registered: ‎10-08-2009
My Device: Bold 9900
My Carrier: Telus

Dialog ok cancel button position

Hi, I currently have dialog button pop up with ok and cancel button on it.

 

The problem is, that the buttons are stacked vertically and I do not know how to change it to horizontal

 

Basically, I do not know how to change from:

 

|OK|

|CANCEL|

 

to:

 

|OK| |CANCEL|

 

 

Please help!

----------------------------------------------------------
Twitter: @gyubok
Developer
Posts: 92
Registered: ‎01-15-2009
My Device: Blackberry 9550

Re: Dialog ok cancel button position

Hi.

 

You need to use layout managers for this.

 

Blackberry Layout managers:

  • HorizontalFieldManager – this layout manager simply lays out the fields you add to it, from left to right, on one row. You can control the width and layout of the fields that you add.
  • FlowFieldManager – this layout manager simply adds fields you add from left to right, and adds as many to one row as possible, before starting a new row, and just keeps adding rows as needed. You can control the width and layout of the fields that you add.

 

Try to create FlowFieldManager(Field.FIELD_VCENTER | Field.FIELD_HCENTER). After that add buttons to it. Add manager to screen.

 

Regards, Dmitry.

Developer
Posts: 660
Registered: ‎10-08-2009
My Device: Bold 9900
My Carrier: Telus

Re: Dialog ok cancel button position

Hi, how do I add buttons to the manager? from what I see, once I choose ok and cancel by

 

 

Dialog.D_OK_CANCEL

 

 

the OK and CANCEL button automatically appear at the bottom.

 

Is there a way to set their long style or sort?

 

 

----------------------------------------------------------
Twitter: @gyubok
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Dialog ok cancel button position

If you are using the standard Dialog control, as far as I know, you will not be able to change this.

 

You will have to create your own PopupScreen if you want the button laid our horizontally. 

Developer
Posts: 55
Registered: ‎07-30-2009
My Device: Not Specified

Re: Dialog ok cancel button position

You either have to create a popup screen as Peter described earlier or have to exend standard dialog class like this:

 

public class CustomDialog extends Dialog
{

 

    HorizontalFieldManager hfmChoices = new HorizontalFieldManager();

 

public CustomDialog(String message)
    {
        super(message, null, null, Dialog.OK, null, Dialog.GLOBAL_STATUS);
        net.rim.device.api.ui.Manager delegate = getDelegate();


        if( delegate instanceof DialogFieldManager)
        {
            DialogFieldManager dfm = (DialogFieldManager)delegate;
            net.rim.device.api.ui.Manager manager =dfm.getCustomManager();
            if( manager != null )
            {                                   
                hfmChoices.deleteAll();
                hfmChoices.add(okButtonFeild);
                hfmChoices.add(cancelButtonField);
                
                manager.insert(hfmChoices, 0);                    
            }
        }
       
    }

 

}

 

 

here okButtonFeild, and cancelButtonField are the button fields you want to arrange on your dialog.

 

----------------------------------------------------------
Got the help you were looking for? Press Kudos on the left to thank.
Please mark posts as solved if you found a solution.

Developer
Posts: 107
Registered: ‎10-06-2010
My Device: Not Specified

Re: Dialog ok cancel button position

Hi Muhammad,

 

You idea sounds really interesting but I cannot get it working.

 

How can you access this class?

 

Nitin

 

 

 

Developer
Posts: 55
Registered: ‎07-30-2009
My Device: Not Specified

Re: Dialog ok cancel button position

You can access this dialog like this.

 

        Dialog dialog = new CustomDialog(message);
        dialog.show();

 

and as I already mentioned that okButtonFeild, and cancelButtonField are the button fields

are the fileds you need to define it inside this CustomDialog and you can attach listener to these fields according to your requirement.

 

----------------------------------------------------------
Got the help you were looking for? Press Kudos on left.
Please mark posts as solved if you found a solution.

 

Contributor
Posts: 26
Registered: ‎11-30-2010
My Device: Not Specified

Re: Dialog ok cancel button position

[ Edited ]

Try this code as custom dialog.

 

Just copy paste code in ur prj.

 

Just add cancel button in button manager.

 

Highlighted
Developer
Posts: 107
Registered: ‎10-06-2010
My Device: Not Specified

Re: Dialog ok cancel button position

Thanks Muhammad,

 

I missed the Dialog.show() trick.

 

All sorted.

 

Nitin