gpt4 book ai didi

android - 如何取消选中 android 中的单选按钮(位于单选组中)?

转载 作者:太空宇宙 更新时间:2023-11-03 12:20:53 24 4
gpt4 key购买 nike

        RadioGroup group=(RadioGroup)findviewbyid(R.id.group);
RadioButton b=(RadioButton)findviewbyid(R.id.button);
RadioButton b1=(RadioButton)findviewbyid(R.id.button1);
RadioButton b2=(RadioButton)findviewbyid(R.id.button2);

group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
selected=(RadioButton)findViewById(checkedId);
userAnswer=selected.getText().toString();
}
});

button=(Button)findviewbyid(R.id.butn);
button.setOnclickListener(new View.OnclickListener(){
void onclick()
{
group.clearCheck();
}
});

我的要求是,每当用户点击下一步按钮时,我需要将单选按钮显示为没有选择的选项。如果用户点击一个选项并且他点击下一步按钮,那么无论他之前点击(选中)的选项是自动选择的下一次,在此之前我需要清除 radio 组中的 radio 按钮,为此我必须做的......

提前致谢......

最佳答案

您是否还在您的 xml 中的 RadioGroup View 中添加了 RadioButtons?如果不是,您需要将它们添加到您正在使用的 RadioGroup 对象中

您需要使用 RadioGroup 中的方法

   void     check(int id)   
Sets the selection to the radio button whose identifier is passed in parameter.


void clearCheck()
/// This method will clear the selection of all the members of RadioGroup

例如,如果 rg 是 RadioGroup 的变量

         rg.check();
rg.clearCheck();

关于android - 如何取消选中 android 中的单选按钮(位于单选组中)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16314639/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com