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
sugarat
Posts: 17
Registered: ‎01-01-2009
My Device: Not Specified
Accepted Solution

two radio buttons on a single line

[ Edited ]

Hi,

 

I cannot make two radio buttons appear on the same line.  I only see the first radio button...


RadioButtonGroup group = new RadioButtonGroup();

RadioButtonField radio1 = new RadioButtonField("one", group, true);
RadioButtonField radio2 = new RadioButtonField("two", group, false);
HorizontalFieldManager hfm = new HorizontalFieldManager();
hfm.add(radio1);
hfm.add(radio2);
add(hfm);

I've tried various style settings on the radio buttons and the horizontal manager.  I also tried extending RadioButtonField to explicitly set the field width.  So far no luck...

 

I am working with version 4.2.1.

 

Any help would be appreciated.

 

Message Edited by sugarat on 01-01-2009 11:39 PM
Message Edited by sugarat on 01-01-2009 11:40 PM
Please use plain text.
Developer
Guest
Posts: 146
Registered: ‎11-05-2008
My Device: Not Specified

Re: two radio buttons on a single line

just do

HorizontalFieldManager hh =  new HorizontalFieldManager();
VerticalFieldManager vf1 =  new VerticalFieldManager();
VerticalFieldManager vf2 =  new VerticalFieldManager();
vf1.add(radio1);
vf2.add(radio2);

hh.add(vf1);

hh.add(vf2);
add(hh);      

Please use plain text.
New Developer
sugarat
Posts: 17
Registered: ‎01-01-2009
My Device: Not Specified

Re: two radio buttons on a single line

Hi,

 

Thank you for your feedback.

 

I tried your suggestion but I'm still seeing the same result, only the first radio button is visible.

 

RadioButtonGroup group = new RadioButtonGroup(); RadioButtonField radio1 = new RadioButtonField("one", group, true); RadioButtonField radio2 = new RadioButtonField("two", group, false); HorizontalFieldManager hh = new HorizontalFieldManager(); VerticalFieldManager vf1 = new VerticalFieldManager(); VerticalFieldManager vf2 = new VerticalFieldManager(); vf1.add(radio1); vf2.add(radio2); hh.add(vf1); hh.add(vf2); add(hh);

I tried adding horizontal scrolling to see if the second radio button is rendered off screen.  I can scroll away so the first radio button disappears but I still don't see the second radio button.

 

Any other suggestions?

 

 

Please use plain text.
Administrator
MSohm
Posts: 14,241
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: two radio buttons on a single line

This sample code works fine in BlackBerry handheld software version 4.5.0.  There is an issue in version 4.2.1 that prevents the second RadioButton from being shown.  This is corrected in version 4.5.0.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
Developer
Developer
rab
Posts: 283
Registered: ‎07-22-2008
My Device: Not Specified

Re: two radio buttons on a single line

From my recollection, I was getting the same behavior. The first radio button is taking the whole space of the manager leaving nothing for the other buttons.

What you need to do is to override the layout of the radio button to set its extent to a smaller width ( like 30 if you do not have text with it).

 

( this is the behavior on 4.2. I did not test it on later versions)

 

 

Rab

Please use plain text.
Developer
zahidalinaqvi
Posts: 445
Registered: ‎10-14-2008
My Device: Blackberry Bold 9000
My Carrier: SingTel

Re: two radio buttons on a single line

import net.rim.device.api.ui.Field; import net.rim.device.api.ui.Manager; public class RadioButtonLayout extends Manager{ public RadioButtonLayout() { super(Manager.VERTICAL_SCROLL | Manager.RIGHTMOST); } protected void sublayout(int width, int height) { Field field; //get total number of fields within this manager int numberOfFields = getFieldCount(); int x = 0; int y = 0; for (int i = 0;i < numberOfFields;i++) { field = getField(i); //get the field setPositionChild(field,x,y); //set the position for the field layoutChild(field, width, height); //lay out the field x += 30; } width=70; height=20; setExtent(width, height); } } RadioButtonGroup rg = new RadioButtonGroup(); RadioButtonLayout v = new RadioButtonLayout(); v.add(new RadioButtonField("", rg, true, RadioButtonField.FIELD_RIGHT)); v.add(new RadioButtonField("", rg, true, RadioButtonField.FIELD_RIGHT)); screen.add(v);

 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Thanks & Regards
Zahid Naqvi | Senior Software Engineer
Please use plain text.
Developer
cjlopez
Posts: 48
Registered: ‎08-01-2008
My Device: Not Specified

Re: two radio buttons on a single line

[ Edited ]

Wow, this solved one of my problem showing some buttons on a colunm instead of a row, but now i'm having another issue.

 

The buttons are painted one over the other like some stair and also the region where are painted is only showing like 1/4 of a button juts like is shown on the next image

Image Hosted by ImageShack.us

There should be 4 buttons and only part of 1 is being painted and part of the next one.

Any idea how can i arrange the button to put then in a row and paint the correctly?

Message Edited by cjlopez on 03-19-2009 06:42 PM
Please use plain text.
Developer
Rajat_10Sep
Posts: 696
Registered: ‎12-02-2008
My Device: Not Specified

Re: two radio buttons on a single line

Hi,

 

I think this will help you out

objRegularCheese = new RadioButtonGroup(); objLeft = new RadioButtonField(" ",objRegularCheese,false,RadioButtonField.NO_USE_ALL_WIDTH); objWhole = new RadioButtonField(" ",objRegularCheese,false,RadioButtonField.NO_USE_ALL_WIDTH); objRight = new RadioButtonField(" ",objRegularCheese,false,RadioButtonField.USE_ALL_WIDTH);

 

Please let me know if this solved your problem or not.
Regards,
Rajat Gupta.
--------------------------------------------------------------------------------
If your problem was get solved then please mark the thread as "Accepted solution" and kudos - your wish
Please use plain text.
Developer
peter_strange
Posts: 19,595
Registered: ‎07-14-2008
My Device: Not Specified

Re: two radio buttons on a single line

Is this your own pop-up or a Dialog?

 

it looks like a standard Dialog.ask().

Please use plain text.
Developer
cjlopez
Posts: 48
Registered: ‎08-01-2008
My Device: Not Specified

Re: two radio buttons on a single line

yeah, its a custom made Dialog using the 4th overcharged contructor of the class

 

 

Dialog(String message, Object[] choices, int[] values, int defaultChoice, Bitmap bitmap, long style)

 

I just set choices and values to null so i don't have any button, defaultChoice is 0 and style is Dialog.GLOBAL_STATUS. Later i add the buttons that are ButtonField. This is the code of the dialog

 

 

// Created the dialog mensaje = new Dialog(.....); // Set the fieldChangeListener of the buttons botonMenu.setChangeListener(lectorCampos); botonSig.setChangeListener(lectorCampos); botonAnt.setChangeListener(lectorCampos); botonNo.setChangeListener(lectorCampos); botonSi.setChangeListener(lectorCampos); // Added the button to the Layout manager posicionCampos.add(botonSi); posicionCampos.add(botonNo); posicionCampos.add(botonMenu); posicionCampos.add(botonAnt); posicionCampos.add(botonSig); // Added the resulting layout to the dialog mensaje.add(posicionCampos); // Set focus on the "botonNo" botonNo.setFocus(); // Returned the resulting dialog to be displayed return mensaje;

 

 This is the dialog displayed on the picture

 

 

 

Please use plain text.