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
MarkyC
Posts: 16
Registered: ‎06-27-2012
My Device: Bold 9900
Accepted Solution

Adding HorizontalFieldManager to the bottom of the screen (to show user a cost)

Hello, I'm trying to pin a HorizontalFieldManager to the bottom of the screen, and have a scrollable VerticalFieldManager above it. I searched around and found that I can do this via overriding my Screen's sublayout method. Note: I know I could use the setStatus() method of a MainScreen class, but I need this screen to be just a Screen and not a MainScreen. Here is a picture of what I am trying to accomplish:

So the blue VerticalFieldManager should be scrollable to allow the user to select toppings for their food item, and the red HorizontalFieldManager should be fixed, so that the user can always see their total (and continue to the next screen to complete their order)

 

Here is the code I have to do so:

protected void sublayout(int width, int height) {
		layoutChild(redManager, width, height);
		setPositionChild(redManager, 0, height);
		layoutChild(blueManager, width, height - redManager.getHeight());
		setPositionChild(blueManager, 0, 0);
		setExtent(width, height);
		}

However, I get an error: IllegalArgumentException: Field is not a child of this manager. The way I add the fields to the screen is like so:

public MyScreen extends Screen {
		...
		public MyScreen() {
			this.add(blueManager);
			this.add(redManager);
		}
}
}

Also, using an AbsoluteFieldManager has also proven not to work

Developer
shism2
Posts: 246
Registered: ‎12-13-2010
My Device: Not Specified

Re: Adding HorizontalFieldManager to the bottom of the screen (to show user a cost)

Please show a complete code listing

Developer
lakshman9687
Posts: 243
Registered: ‎07-22-2011
My Device: BlackBerry Z10

Re: Adding HorizontalFieldManager to the bottom of the screen (to show user a cost)

Hi,

 

Use setSatus() method to add any field to bottom of your screen..

 

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.

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

Re: Adding HorizontalFieldManager to the bottom of the screen (to show user a cost)

Hi,

VerticalFieldManager ScrollingVFM = new VerticalFieldManager(){
protected void sublayout(int width, int height) {
layoutChild(redManager, width, height);
setPositionChild(redManager, 0, height);
layoutChild(blueManager, width, height - redManager.getHeight());
setPositionChild(blueManager, 0, 0);
setExtent(width, height);
}
}
Super Contributor
pp
Posts: 278
Registered: ‎11-04-2010
My Device: 4.5 and above

Re: Adding HorizontalFieldManager to the bottom of the screen (to show user a cost)

Hi, 

 

sorry prev post was by mistake... try this,

 

VerticalFieldManager ScrollingVFM = new VerticalFieldManager(){
protected void sublayout(int width, int height) {

super.sublayout(width, height);
setExtent(Display.getwidth(), Display.getHeight() - bottomHFMHeight);
}
}

 

 

add this to screen and add your bottom hfm to screen

 

Regards,

pp

Contributor
MarkyC
Posts: 16
Registered: ‎06-27-2012
My Device: Bold 9900

Re: Adding HorizontalFieldManager to the bottom of the screen (to show user a cost)

Thank you very much pp. That solution seems so obvious now! I don't know why my initial instinct was to override the sublayout() of the Screen when the Manager makes more sense :Sweatdrop:

Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Device: various

Re: Adding HorizontalFieldManager to the bottom of the screen (to show user a cost)


pp wrote:

 

VerticalFieldManager ScrollingVFM = new VerticalFieldManager(){
protected void sublayout(int width, int height) {

super.sublayout(width, height);
setExtent(Display.getwidth(), Display.getHeight() - bottomHFMHeight);
}
}

 

 

add this to screen and add your bottom hfm to screen

 

Regards,

pp


Unfortunately, this is a very risky solution. First, you tell the VFM (by the way, you forgot to add VERTICAL_SCROLL as a parameter there) that is has the whole height in super.sublayout call, then you manually override that. It will only confuse the manager. If you want to do it properly, try this:

VerticalFieldManager ScrollingVFM = new VerticalFieldManager(VERTICAL_SCROLL){
  protected void sublayout(int width, int height) {
    super.sublayout(width, Math.min(height, Display.getHeight() - bottomHFMHeight));
  }
};

 There is, however, a pre-made solution available - check MainScreen.setStatus method. You can find more about it here:

MainScreen explained

 

Good luck!

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!