OS 6上的RadioButtonGroup问题

时间:2011-01-21 08:49:02

标签: blackberry

以下代码在Blackberry OS 4和5中运行良好。但在OS 6中,它不显示“Female”单选按钮选项。任何人都可以为此提供理由,建议一个适用于所有Blackberry OS的解决方案吗?

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;
}

1 个答案:

答案 0 :(得分:0)

我得到了它的工作。这是Blackberry OS 6的一个错误,如果你在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);
     }
}