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
Trusted Contributor
Himanshu_berry
Posts: 138
Registered: ‎04-19-2012
My Device: No
Accepted Solution

Two RadioButton in single line with any idea...

Hello 

Can i add two RadioButton in singel line...

i m using HorizontalFieldManager with it 

but only First Button is visible.................................give me any good and simple solution for this plz help me.

 

Thanks

Himanshu 

Beginner

Developer
MohammedAziz
Posts: 139
Registered: ‎02-23-2012
My Device: Blackberry bold

Re: Two RadioButton in single line with any idea...

Yes, you can add two radio buttons on one line.

For that you need to set layout for Horizental Field manager.

warm regards
Mohammed Aziz
Developer
MohammedAziz
Posts: 139
Registered: ‎02-23-2012
My Device: Blackberry bold

Re: Two RadioButton in single line with any idea...

After doing that please post your code as well.....
warm regards
Mohammed Aziz
Trusted Contributor
Himanshu_berry
Posts: 138
Registered: ‎04-19-2012
My Device: No

Re: Two RadioButton in single line with any idea...

actully other also give that solution .its working but 

it also hides all fields which are placed just below RadioButtons..

 

plz send code Sir.

Trusted Contributor
Himanshu_berry
Posts: 138
Registered: ‎04-19-2012
My Device: No

Re: Two RadioButton in single line with any idea...

i use this but it hides all fields below the radiobuttons.

 

 

RadioButtonGroup group = new RadioButtonGroup();

final RadioButtonField radio1 = new RadioButtonField("one", group, true);
final RadioButtonField radio2 = new RadioButtonField("two", group, false);
HorizontalFieldManager hfm = new HorizontalFieldManager(){
protected void sublayout(int maxWidth, int maxHeight) {
setPositionChild(radio1, 0, 0);
layoutChild(radio1, 100, 50);
setPositionChild(radio2, 150, 0);
layoutChild(radio2, 100, 50);
setExtent(maxWidth, maxHeight);
}
};
hfm.add(radio1);
hfm.add(radio2);
add(hfm);

Developer
MohammedAziz
Posts: 139
Registered: ‎02-23-2012
My Device: Blackberry bold

Re: Two RadioButton in single line with any idea...

Please Find the below Code and try it and let me know......

 

radioButtonGroup = new RadioButtonGroup();

		radioButtonField = new RadioButtonField("Radio 1", radioButtonGroup,
				true, 0) {
			protected void layout(int arg0, int arg1) {
				setExtent(Display.getWidth() / 2, arg1);
				super.layout(Display.getWidth() / 2, arg1);
			};
		};
		radioButtonField1 = new RadioButtonField("Radio 2", radioButtonGroup,
				false, 0) {

			protected void layout(int arg0, int arg1) {
				setExtent(Display.getWidth() / 2, arg1);
				super.layout(Display.getWidth() / 2, arg1);
			};

		};

		HorizontalFieldManager hfmFieldManager = new HorizontalFieldManager() {
			protected void sublayout(int maxWidth, int maxHeight) {
				setExtent(Display.getWidth(), maxHeight);
				super.sublayout(Display.getWidth(), maxHeight);
			}
		};

		hfmFieldManager.add(radioButtonField);
		hfmFieldManager.add(radioButtonField1);

		add(hfmFieldManager);

		add(new LabelField("This label is below the two radio buttons",FOCUSABLE));
		add(new ButtonField("Click ME!"));

 

warm regards
Mohammed Aziz
Trusted Contributor
Himanshu_berry
Posts: 138
Registered: ‎04-19-2012
My Device: No

Re: Two RadioButton in single line with any idea...

:Yes: thanks again Mohammed sir....perfect solution.

Namaskar from my side.

 

 

 

Thanks 

Himanshu

Developer
QuiteSimple
Posts: 1,452
Registered: ‎11-06-2009
My Device: Torch 9810

Re: Two RadioButton in single line with any idea...

Just for reference, I fount it easier to use GridFieldManager and to place the radiobuttons inside (it is 3-radiobuttons example):

 

		GridFieldManager grid = new GridFieldManager(1,3, GridFieldManager.FIXED_SIZE);
		int width = Display.getWidth()/3 - 10; // 10 - some padding
		grid.setColumnProperty(0, GridFieldManager.FIXED_SIZE, width);
		grid.setColumnProperty(1, GridFieldManager.FIXED_SIZE, width);
		grid.setColumnProperty(2, GridFieldManager.FIXED_SIZE, width);

		grid.add(new RadioButtonField("Test", typeRadioGroup, false));
		grid.add(new RadioButtonField("Test1", typeRadioGroup, false));
		grid.add(new RadioButtonField("Test2", typeRadioGroup, false));
		add(grid);

 



"When you become a level 3 developer, you learn to communicate over the ether. I'm told that level 5 developers are ascend into a higher level of existence beyond the physical realm." gord888 @ crackberry