取消选中android中的单选按钮

时间:2015-01-18 07:41:44

标签: java android radio-button uncheck

我是java中的新手并且radioButtondelivery.setSelected(false);遇到问题,radioButtondelivery处于红线下,请帮助我。

public void onRadioButtonClicked(View view) {
    // Is the button now checked?
    boolean checked = ((RadioButton) view).isChecked();

    // Check which radio button was clicked
    switch(view.getId()) {
        case R.id.radioButtonpickup:
            if (checked)

                radioButtondelivery.setSelected(false);

            break;
        case R.id.radioButtondelivery:
            if (checked)
                // code here
            break;
    }
}

1 个答案:

答案 0 :(得分:1)

使用setChecked()

radioButtondelivery.setChecked(false);

但是您必须考虑使用RadioGroup,一旦您选择其中一个,它会自动取消选中其他单选按钮