2011-01-21 109 views
0

以下代码在Blackberry OS 4和5中运行良好。但在OS 6中,它不显示“女性”单选按钮选项。任何人都可以为此提出理由,建议适用于所有Blackberry OS的解决方案?操作系统6上的RadioButtonGroup问题

LabelField genderLabelField = new LabelField("Gender:"); 
RadioButtonGroup radioButtonGroup = new RadioButtonGroup(); 

RadioButtonField maleRadioField = new RadioButtonField("Male"); 
RadioButtonField femaleRadioField = new RadioButtonField("Female"); 

private VerticalFieldManager createUI() 
{  
    VerticalFieldManager vfmForm = new VerticalFieldManager(); 

    vfmForm.add(joinf2fLabelField); 

    firstNameEditField.setMargin(0, 0, 5, 0); 
    vfmForm.add(firstNameLabelField); 
    vfmForm.add(firstNameEditField); 

    lastNameEditField.setMargin(0, 0, 5, 0); 
    vfmForm.add(lastNameLabelField); 
    vfmForm.add(lastNameEditField); 

    emailEditField.setMargin(0, 0, 5, 0); 
    vfmForm.add(emailLabelField); 
    vfmForm.add(emailEditField); 

    passwordEditField.setMargin(0, 0, 5, 0); 
    vfmForm.add(passwordLabelField); 
    vfmForm.add(passwordEditField); 

    confirmPasswordEditField.setMargin(0, 0, 5, 0); 
    vfmForm.add(confirmPasswordLabelField); 
    vfmForm.add(confirmPasswordEditField); 

    vfmForm.add(genderLabelField); 

    radioButtonGroup.add(maleRadioField); 
    radioButtonGroup.add(femaleRadioField); 

    HorizontalFieldManager hfmGender = new HorizontalFieldManager(); 

    maleRadioField.setMargin(new XYEdges(0, 5, 0, 0)); 
    hfmGender.add(maleRadioField); 
    hfmGender.add(femaleRadioField); 

    hfmGender.setMargin(new XYEdges(5, 0, 10, 0)); 
    vfmForm.add(hfmGender); 

    vfmForm.add(dateField); 

    HorizontalFieldManager hfmButtons = new HorizontalFieldManager(FIELD_HCENTER | FIELD_VCENTER); 

    hfmButtons.add(submitButton); 
    submitButton.setMargin(new XYEdges(0, 10, 0, 0)); 

    hfmButtons.add(cancelButton); 
    hfmButtons.setMargin(new XYEdges(10, 0, 5, 0)); 

    vfmForm.add(hfmButtons);   

    return vfmForm; 
} 

回答

0

我明白了。这是Blackberry OS 6的一个bug,如果您在Horizo​​ntalFieldManager中有两个单选按钮,它将不会显示第二个单选按钮。您只需要扩展RadioButtonField并将其用于替换原始文件。

class RadioButtonFieldPatch extends RadioButtonField 
{ 
    RadioButtonFieldPatch(String label) 
    { 
     super(label); 
    } 

    RadioButtonFieldPatch(String label, RadioButtonGroup group, boolean selected) 
    { 
     super(label, group, selected); 
    } 

    protected void layout(int width, int height) 
    { 
     int pWidth = this.getPreferredWidth(); 
     setExtent(pWidth, height); 
     super.layout(pWidth, height); 
    } 
}