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

Posts: 170
Registered: ‎01-26-2009
My Device: Not Specified
Accepted Solution

RadioButtonField in Horizontal Line

Hello Everyone


Is there a way to put 3 or 4 RadioButtonFields in Horizontal line.


I tried adding them into HorizontalFieldManager, did not work.




Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified

Re: RadioButtonField in Horizontal Line

HorizontalFieldManager will not work in this case.

You will need CustomLayout for this purpose.


Try with this Manager:


public class RadioButtonLayout extends Manager { public RadioButtonLayout() { super(Manager.VERTICAL_SCROLL | Manager.RIGHTMOST); } protected void sublayout(int width, int height) { Field field; int numberOfFields = getFieldCount(); int x = 0; int y = 0; int maxHeight = 0; for (int i = 0;i < numberOfFields;i++) { field = getField(i); setPositionChild(field,x,y); layoutChild(field, field.getPreferredWidth(), field.getPreferredHeight()); x += field.getWidth() + 5; if (maxHeight < field.getHeight()) { maxHeight = field.getHeight(); } } width = x; height = maxHeight; setExtent(width, height); } }


And from MainScreen


RadioButtonGroup btnGroup = new RadioButtonGroup(); RadioButtonLayout radioBtnLayout = new RadioButtonLayout(); radioBtnLayout.add(new RadioButtonField("Btn1", btnGroup, true, RadioButtonField.FIELD_RIGHT)); radioBtnLayout.add(new RadioButtonField("Btn2", btnGroup, true, RadioButtonField.FIELD_RIGHT)); radioBtnLayout.add(new RadioButtonField("Btn3", btnGroup, true, RadioButtonField.FIELD_RIGHT)); this.add(radioBtnLayout);