当前位置 : 主页 > 手机开发 > android >

如何取消选中android中的单选按钮(在radiogroup中)?

来源:互联网 收集:自由互联 发布时间:2021-06-11
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.setOnCheckedC
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();
       }
      });

我的要求是每当用户点击下一个按钮时我需要显示单选按钮作为选项而没有选择.如果用户单击一个选项,他点击下一个按钮,然后点击他之前单击(选中)的选项,下次自动选择在此之前,我需要清除放射线组中的无线电按钮,因为我必须做的……

提前致谢…….

您还在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();
网友评论