3
        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();
       }
      });

私の要件は、ユーザーが次のボタンをクリックするたびに、ラジオボタンを選択せず​​にオプションとして表示する必要があることです. 、その前に、私がしなければならないことのためにラジオグループのラジオボタンをクリアする必要があります......

前もって感謝します.......

4

1 に答える 1

9

また、xml の RadioGroup ビュー内に 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();
于 2013-05-01T08:04:36.197 に答える