05-23-2012 10:16 AM
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));
Solved! Go to Solution.
05-23-2012 10:44 AM
05-23-2012 10:49 AM
05-23-2012 10:57 AM
05-23-2012 11:29 AM
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
), this will restrict the width of your RadioButtonField and let the other one have some room in the same HorizontalFieldManager.
Good luck!
05-23-2012 12:26 PM
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.F IELD_VCENTER) { protected void layout(int maxWidth, int maxHeight) { super.layout(Math.min(maxWidth, 60), maxHeight); }}); hfm.add(new RadioButtonField("jha",rbg,true,RadioButtonField.F IELD_VCENTER) { protected void layout(int maxWidth, int maxHeight) { super.layout(Math.min(maxWidth, 60), maxHeight); }}); add(hfm); } }
Thanks
Pawan
05-24-2012 04:32 PM
Thank you so much Pankajac12
. The code worked for me.
I just changed the maxwidth from 60 to 250.
Thanks again!