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
Sultan14
Posts: 47
Registered: ‎05-11-2012
My Device: Blackberry Bold 9930
My Carrier: Tmobile
Accepted Solution

How to horizontally align two radio buttons?

Hi,

I'm trying to add two radio button to my application. Is there an easy way to align two radio buttons  Horizontally on the screen without using the gridFieldManager?

 

Thank you.

 

My code

 

RadioButtonGroup rbg = newRadioButtonGroup();

add(new RadioButtonField("AAA",rbg,true,RadioButtonField.FIELD_VCENTER));

add(new RadioButtonField("BBB",rbg,false,RadioButtonField.FIELD_VCENTER));

 

 

 

 

Please use plain text.
Developer
simon_hain
Posts: 15,853
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: How to horizontally align two radio buttons?

did you try a HorizontalFieldManager?
----------------------------------------------------------
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.
@SimonHain on twitter
Please use plain text.
New Developer
Sultan14
Posts: 47
Registered: ‎05-11-2012
My Device: Blackberry Bold 9930
My Carrier: Tmobile

Re: How to horizontally align two radio buttons?

Thanks Simon for the quick response. And yes, Actually I tried it but it didn't work . Maybe I need to build a specific gridManager for this situation. What do you think? And thank you again.
Please use plain text.
Developer
simon_hain
Posts: 15,853
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: How to horizontally align two radio buttons?

ok, i see, this is one of the fields that uses all width.
in 7.0 there is a style to supress that, but i guess it won't help earlier (you can try the numerical value, maybe it works!)
http://www.blackberry.com/developers/docs/7.1.0api/net/rim/device/api/ui/component/RadioButtonField....

second easiest solution would be to overwrite http://www.blackberry.com/developers/docs/7.1.0api/net/rim/device/api/ui/component/RadioButtonField.... to return your desired value.

if that does not work, or you find it too messy, create a custom layout, see http://supportforums.blackberry.com/t5/Java-Development/How-to-Extend-Manager/ta-p/446749
----------------------------------------------------------
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.
@SimonHain on twitter
Please use plain text.
Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: How to horizontally align two radio buttons?

There is also a universal trick solving the problem.

You can restrict width of any built-in field (such as RadioButtonField) using the following simple layout override:

protected void layout(int maxWidth, int maxHeight) {
  super.layout(Math.min(maxWidth, myDesiredWidth), maxHeight);
}

Since fields created by RIM dutifully obey the limits passed to them (unlike many custom fields I see here in the forums :smileyhappy:), this will restrict the width of your RadioButtonField and let the other one have some room in the same HorizontalFieldManager.

 

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!
Please use plain text.
Developer
pankajace12
Posts: 192
Registered: ‎04-30-2011
My Device: Software
My Carrier: Airtel

Re: How to horizontally align two radio buttons?

Hi Sultan

 

import net.rim.device.api.ui.component.RadioButtonField;
import net.rim.device.api.ui.component.RadioButtonGroup;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;

public class pkj extends MainScreen{
public pkj() {
	// TODO Auto-generated constructor stub
 
	HorizontalFieldManager hfm = new HorizontalFieldManager();
	 
	RadioButtonGroup rbg = new RadioButtonGroup();
	hfm.add(new RadioButtonField("AAA",rbg,true,RadioButtonField.FIELD_VCENTER)
	{
	protected void layout(int maxWidth, int maxHeight) {
		  super.layout(Math.min(maxWidth, 60), maxHeight);
	}});
	
	hfm.add(new RadioButtonField("jha",rbg,true,RadioButtonField.FIELD_VCENTER)
	{
	protected void layout(int maxWidth, int maxHeight) {
		  super.layout(Math.min(maxWidth, 60), maxHeight);
	}});
	
	add(hfm);
}
}

 Thanks
Pawan 

Please use plain text.
New Developer
Sultan14
Posts: 47
Registered: ‎05-11-2012
My Device: Blackberry Bold 9930
My Carrier: Tmobile

Re: How to horizontally align two radio buttons?

Thank you so much Pankajac12 :smileyhappy:. The code worked for me. 

I just changed the maxwidth from 60 to 250.

 

Thanks again!

Please use plain text.