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

Sha*_*kar 3 android radio-button

        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();
       }
      });
Run Code Online (Sandbox Code Playgroud)

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

提前致谢.......

use*_*_CC 7

您还在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
Run Code Online (Sandbox Code Playgroud)

例如,如果rg是RadioGroup的变量

         rg.check();
         rg.clearCheck();
Run Code Online (Sandbox Code Playgroud)