选择新值后,默认无线电值未能清除或取消选择

发布于 2025-01-29 07:13:41 字数 1350 浏览 1 评论 0原文

在循环中,我已经进行了检查,但是在选择新值之后,我不会脱颖而出。两个值都选择了先前的setchecked值和新选择的值。

textInputLayout = new TextInputLayout(context);

textInputLayout.setPadding(0, -65, 0, -20);
for (int i = 0; i < formElement.getRadioOptions().size(); i++) {
    RadioButton radiobutton1 = new RadioButton(context);
    radiobutton1.setText(formElement.getRadioOptions().get(i).getValue());
    radiobutton1.setTextSize(TypedValue.COMPLEX_UNIT_PX, context.getResources().getDimension(R.dimen.meetingNoteCL));

    radiobutton1.setChecked(formElement.getValue().equals(formElement.getRadioOptions().get(i).getValue()));

    rg.addView(radiobutton1);
}
textInputLayout.setTypeface(FontUtils.getFontTypeRegular(context));

rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        // checkedId is the RadioButton selected
        int radioButtonID = group.getCheckedRadioButtonId();
        View radioButton = group.findViewById(radioButtonID);
        int idx = group.indexOfChild(radioButton);

        formElement.setKey(formElement.getRadioOptions().get(idx).getKey());
        formElement.setValue(formElement.getRadioOptions().get(idx).getValue());

    }
});


viewMap.put(formElement.getTagOrToString(), rg);
addViewToView(textInputLayout, rg);

in for loop I have setChecked, but after choosing new value does not get deselected. Both the values get selected which is previous setChecked value and newly selected value.

textInputLayout = new TextInputLayout(context);

textInputLayout.setPadding(0, -65, 0, -20);
for (int i = 0; i < formElement.getRadioOptions().size(); i++) {
    RadioButton radiobutton1 = new RadioButton(context);
    radiobutton1.setText(formElement.getRadioOptions().get(i).getValue());
    radiobutton1.setTextSize(TypedValue.COMPLEX_UNIT_PX, context.getResources().getDimension(R.dimen.meetingNoteCL));

    radiobutton1.setChecked(formElement.getValue().equals(formElement.getRadioOptions().get(i).getValue()));

    rg.addView(radiobutton1);
}
textInputLayout.setTypeface(FontUtils.getFontTypeRegular(context));

rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        // checkedId is the RadioButton selected
        int radioButtonID = group.getCheckedRadioButtonId();
        View radioButton = group.findViewById(radioButtonID);
        int idx = group.indexOfChild(radioButton);

        formElement.setKey(formElement.getRadioOptions().get(idx).getKey());
        formElement.setValue(formElement.getRadioOptions().get(idx).getValue());

    }
});


viewMap.put(formElement.getTagOrToString(), rg);
addViewToView(textInputLayout, rg);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文