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
mapleleafs90
Posts: 374
Registered: ‎02-12-2011
My Device: Bold 9780
Accepted Solution

HorizontalFieldManager Problem

I've tripple checked this layout and I dont see why there is a problem.. When I want to have 2 edit fields side by side using two vertical field managers in one horizontal, the 2nd vertical field manager doesn't show up at all. In the end, editfield0 should be on the left and editfield1 directly beside on the right

 

 

 HorizontalFieldManager hfm1 = new HorizontalFieldManager();
 VerticalFieldManager vfm1 = new VerticalFieldManager();
 VerticalFieldManager vfm2 = new VerticalFieldManager();
			  
 vfm1.add(Label0);
 vfm1.add(EditField0);
 vfm1.add(Profile); //Radio buttons
 vfm1.add(Profile1);
 vfm1.add(Profile2);
 vfm1.add(Profile3);
 vfm1.add(Profile4);
 vfm1.add(Profile5);
          
 vfm2.add(Label1);
 vfm2.add(EditField1);
 vfm2.add(Label2);
 vfm2.add(EditField2);
	          
 hfm1.add(vfm1);
 hfm1.add(vfm2);
 add(hfm1);

 If I comment out editfield0 the whole thing works, if I comment out editfield1 its still messed up

 

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

Re: HorizontalFieldManager Problem

There is a hidden feature of EditField - it is "width hungry". Any EditField, no matter how many maxChars it has, always behaves as though USE_ALL_WIDTH were in effect. This makes vfm1 occupy all given width as well, not leaving any room for vmf2.

In order to curb the field's appetite, define your edit field like this:

 

EditField editField0 = new EditField(...) {
  protected void layout(int width, int height) {
    // calculate (or precalculate elsewhere) the desired width
    int myMaxWidth = <...>;
    // use it!
    super.layout(Math.min(width, myMaxWidth), height);
  }
};

 

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!
Developer
mapleleafs90
Posts: 374
Registered: ‎02-12-2011
My Device: Bold 9780

Re: HorizontalFieldManager Problem

When I am testing on the emulator for the bold 9700 it works fine, and I move it on to my bold 9780 and its the same as before, the 2nd vertical manager on the right is missing.

 

Would this be caused because I am emulating OS5 but testing on OS6? If so, what is the fix for OS6 devices?

Developer
mapleleafs90
Posts: 374
Registered: ‎02-12-2011
My Device: Bold 9780

Re: HorizontalFieldManager Problem

And thats not even with having 2 editfields side by side but rather

 

EDITFIELD

RADIO ------- EDITFIELD
RADIO ------- EDITFIELD
RADIO -------BUTTON BUTTON
RADIO

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

Re: HorizontalFieldManager Problem

After researching this a little bit more, I found that RadioButton is quite inconsistent - on some platforms it, too, takes the whole width. So you might need the same exercise with your RadioButtonFields. Try it and see if it works.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Developer
mapleleafs90
Posts: 374
Registered: ‎02-12-2011
My Device: Bold 9780

Re: HorizontalFieldManager Problem

I find that very dumb, all I want it to do is take up as much of the screen as it needs and no more. So when I move the app from device to device with different screen sizes there aren't any layout issues.

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

Re: HorizontalFieldManager Problem

You are not alone - there are many small and not so small inconsistencies between different BlackBerry models and OS versions.

As for your initial problem - since you cannot rely on either EditField or RadioButtonField to "behave", add them normally to your managers, but create your managers differently:

 

HorizontalFieldManager hfm1 = new HorizontalFieldManager();
VerticalFieldManager vfm1 = new VerticalFieldManager() {
  protected void sublayout(int maxWidth, int maxHeight) {
    super.sublayout(maxWidth / 2, maxHeight);
  }
};
VerticalFieldManager vfm2 = new VerticalFieldManager();

This way your left side manager is guaranteed to take only half of the screen, leaving enough room on the right.

So drop your layout overrides from the fields and "squeeze" the whole Manager :smileyhappy:

 

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Developer
mapleleafs90
Posts: 374
Registered: ‎02-12-2011
My Device: Bold 9780

Re: HorizontalFieldManager Problem

Thanks, that is a very good solution!