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
New Developer
Posts: 9
Registered: ‎05-05-2009
My Device: Not Specified
Accepted Solution

CustomLayoutManager does not show second instance.

Hi there is want to make a CustomLayoutManager that makes it possible to set the width of each field with a fixed value.I want to use this to align several rows by adding several instances of this Manager.


When I add two of the CustomLayoutManager to the default VerticalLayoutManager of the screen the second one does not appear and the little scroll arrow appears. 

 

I think it has something to do with the allotted vertical space of the CustomLayoutManager.  When I use an normal HorizontalLayoutManager  the two rows appear and little scroll arrow does not appear.


Any assistance would be greatly appreciated.

Wil

 

 

package sili.bb; import net.rim.device.api.ui.Field; import net.rim.device.api.ui.container.HorizontalFieldManager; class CustomFieldManager extends HorizontalFieldManager { public CustomFieldManager() { } public int getPreferredWidth() { return 320; } public int getPreferredHeight() { int height = 0; int numberOfFields = getFieldCount(); for (int i = 0; i < numberOfFields; ++i) if (getField(i).getPreferredHeight() > height) height = getField(i).getPreferredHeight(); return height; } protected void sublayout(int width, int height) { int x = 0; int y = 0; Field field; int numberOfFields = getFieldCount(); for (int i = 0; i < numberOfFields; ++i) { field = getField(i); layoutChild(field, width, height); setPositionChild(field, x, y); x += field.getPreferredWidth()+20; } setExtent(width, height); } }

 

package sili.bb; import net.rim.device.api.ui.UiApplication; class LayoutTest extends UiApplication { public static void main(String[] args) { LayoutTest myApp = new LayoutTest(); myApp.enterEventDispatcher(); } LayoutTest() { StartScreen startScreen = new StartScreen(); this.pushScreen(startScreen); } }

 

package sili.bb; import net.rim.device.api.ui.component.LabelField; import net.rim.device.api.ui.container.MainScreen; class StartScreen extends MainScreen { StartScreen() { this.setTitle("LayoutTest"); LabelField lf1 = new LabelField("one"); LabelField lf2 = new LabelField("two"); LabelField lf3 = new LabelField("three"); LabelField lf4 = new LabelField("four"); CustomFieldManager cfm1 = new CustomFieldManager(); CustomFieldManager cfm2 = new CustomFieldManager(); cfm1.add(lf1); cfm1.add(lf2); cfm2.add(lf3); cfm2.add(lf4); this.add(cfm2); this.add(cfm1); } }

 

 

 

 

Developer
Posts: 178
Registered: ‎07-29-2008
My Device: Not Specified

Re: CustomLayoutManager does not show second instance.

The issue here is your setExtent() call in your layout message.

 

what you want to do is call setExtent(getPreferredWidth(),getPreferredHeight())  because the screen has an internal VerticalFieldManager it will call your custom manager's sublayou() with a height of MAX_INT.  What your doing is setting your first manager to be really really tall.  your second manager is being added, it's just way way down at the bottom.

Highlighted
New Developer
Posts: 9
Registered: ‎05-05-2009
My Device: Not Specified

Re: CustomLayoutManager does not show second instance.

Many thanks, I was struggling with this a long long long day.  You have made my day!!!!  Smiley Very Happy