【问题标题】:how to fix CheckBox?如何修复复选框?
【发布时间】:2018-01-22 15:29:25
【问题描述】:

我有六个复选框,所以我需要如果用户选中复选框,他可以看到可用的橙色按钮,但如果他不选中该按钮是灰色且不可用。
所以,我尝试这样做,但问题是,如果用户选中所有复选框并且在未选中之后,按钮灰色仍然可用并且不会变为橙色。

这是我的一个复选框的代码:

 mCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

            if (mCheckBox.isChecked()) {
                mImageButtonOrange.setEnabled(true);
                mImageButtonOrange.setVisibility(View.VISIBLE);
                mImageButtonError.setVisibility(View.GONE);
            } else {
                mImageButtonOrange.setEnabled(false);
                mImageButtonOrange.setVisibility(View.VISIBLE);
                mImageButtonError.setVisibility(View.VISIBLE);
            }

checkBox被勾选,橙色按钮可用:

enter image description here

所以,在我们检查之后,我们想取消选中,按钮灰色可用虽然,复选框被选中并且按钮橙色不可用: enter image description here

那么,我该如何改变这一点,在我取消选中复选框并且我有另一个复选框进行检查后,按钮橙色是可见性而按钮灰色消失了?

【问题讨论】:

  • 将您的复选框添加到列表中,并为每个复选框添加 setOnCheckedChangeListener。然后,如果列表中的任何一个复选框被选中,您可以显示橙色按钮,否则当所有复选框都未选中时显示灰色按钮。
  • 非常感谢@PraveenSingh 的评论,你有例子吗?

标签: android checkbox


【解决方案1】:

您也可以使用RadioGroup 来实现相同的功能,并使用RadioGroup onCheckedChange 事件管理橙色Button 可见性。

RadioButton里面的所有<RadioGroup></RadioGroup>放到xml里面。

【讨论】:

    猜你喜欢
    • 2017-03-20
    • 1970-01-01
    • 2023-03-22
    • 2020-10-31
    • 1970-01-01
    • 1970-01-01
    • 2015-09-06
    • 2015-01-27
    • 1970-01-01
    相关资源
    最近更新 更多