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
Highlighted
Contributor
Posts: 49
Registered: ‎05-02-2012
My Device: Bold 9790
My Carrier: Wind Mobile
Accepted Solution

Set a field to the bottom of the screen without setStatus()

Hi there,

 

I want to set a field to always be at the bottom of the screen without using setStatus() since it is opaque. Most threads I've looked at have a complicated layout on top of wanting a field at the bottom. I have a very flexible layout, right now I just have my fields added to the main manager. Is there a good way to push a field to the bottom of the screen? Or is it only possible by overriding some manager's functions?

 

Ben

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

Re: Set a field to the bottom of the screen without setStatus()

This is not trivial.

 

You need to create a manager and tell it to use all height and not be vertically scrollable.  So the dimensions that get passed into its sublayout will give you the full height you have available. 

 

Now you should add two Managers to this Manager.  The first one is the one you will add all you Fields too - it will be a standard VFM, so that it is scrolling.  The second one will be the stuff you want at the bottom of the screen.

 

In sublayout you will layout the second Field first, get its height and then set its position so it is at the bottom.  This will also give you the area that is available for your scrolling Manager.  You will then layout this Manager telling it that it is restrcted to the height you have left.  As it is scrolling this will not worry it,

 

Lastly in sublayout you will setExtent making sure you use the full height you have been given. 

 

For further information:

http://supportforums.blackberry.com/t5/Java-Development/How-to-Extend-Manager/ta-p/446749

http://supportforums.blackberry.com/t5/Java-Development/Create-a-custom-layout-manager-for-a-screen/...

 

 

Contributor
Posts: 49
Registered: ‎05-02-2012
My Device: Bold 9790
My Carrier: Wind Mobile

Re: Set a field to the bottom of the screen without setStatus()

[ Edited ]

Something like this?

 

HorizontalFieldManager hfm = new HorizontalFieldManager(USE_ALL_HEIGHT | NO_VERTICAL_SCROLL) {
   protected void sublayout(int maxWidth, int maxHeight) {
      setPositionChild(Manager2, 0, Display.getHeight()-Manager2.getPreferredHeight());

      layoutChild(Manager1, maxWidth, maxHeight-Manager2.getPreferredHeight());
      setExtent(maxWidth, maxHeight);
   }
};

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

Re: Set a field to the bottom of the screen without setStatus()

Good attempt!  It might work too, I'm not sure. 

 

However

1) I would use a VFM, rather than a HFM as the basis for this.

2) You should not use Display.getHeight() as you do, remember that you have told the Manager you are adding this to, that you want to USE_ALL_HEIGHT and not scroll, so it should pass in, in the variable maxHeight, the actual height you have to play with. 

3) I would not rely on Manager2 giving the correct value for getPreferredHeight.  Instead do this:

layoutChild(Manager2, maxWidth, maxHeight);

now Manager2.getHeight() will tell you exactly how much space it needs.  So use that to position Manager2 and to determine the space left for Manager1 when you layout Manager1.

4) I would setPositionChild Manager1 to 0,0

5) When you specify setExtent, you want to tell it the width you actually need.  So ask Manager1 and Manager2 what their widths are (once they have been laid out) - the width you actually need will be the maximum of these two values. 

Contributor
Posts: 49
Registered: ‎05-02-2012
My Device: Bold 9790
My Carrier: Wind Mobile

Re: Set a field to the bottom of the screen without setStatus()

[ Edited ]

Hi there! Thanks for those tips, they helped a lot. I have one more problem. With this:

 

final VerticalFieldManager Manager1 = new VerticalFieldManager();
final VerticalFieldManager Manager2 = new VerticalFieldManager();

Manager1.add(new RichTextField("This is Manager 1"));
Manager2.add(new RichTextField("This is Manager 2"));
                
VerticalFieldManager vfm = new VerticalFieldManager(USE_ALL_HEIGHT | NO_VERTICAL_SCROLL) {
    protected void sublayout(int maxWidth, int maxHeight) {
        
        layoutChild(Manager2, maxWidth, maxHeight);
        setPositionChild(Manager2, 0, maxHeight-Manager2.getHeight());
        
        layoutChild(Manager1, maxWidth, maxHeight-Manager2.getHeight());
        setPositionChild(Manager1, 0, 0);
        
        if(Date.getWidth() > Manager2.getWidth()) {
            setExtent(Manager1.getWidth(), maxHeight);
        }
        else {
            setExtent(Manager2.getWidth(), maxHeight);
        }
    }
};

vfm.add(Manager1);
vfm.add(Manager2);

add(vfm);

 

I get an infinitely long screen, but the Managers are placed where they're supposed to be! I think it must be something with the height of Manager1 since I can scroll between the two RichTextFields?

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

Re: Set a field to the bottom of the screen without setStatus()

Ah yes, silly me.

 

I presume you are adding this to a MainScreen.  Define the MainScreen with

USE_ALL_HEIGHT | NO_VERTICAL_SCROLL.

 

Actually I am not the expert here, the person you want is the person who wrote this article that I think you should read:

http://supportforums.blackberry.com/t5/Java-Development/MainScreen-explained/ta-p/606644

 

I'm just filling in because I know he is not around!

 

Anyway, I hope by reviewing that article and changing the MainScreen style, you get it working without the infinitely long screen....

Contributor
Posts: 49
Registered: ‎05-02-2012
My Device: Bold 9790
My Carrier: Wind Mobile

Re: Set a field to the bottom of the screen without setStatus()

It works now! I added super(USE_ALL_HEIGHT | NO_VERTICAL_SCROLL); instead of just super(); to my screen object and it works like a charm.

 

Thank you for the article,

Ben