2013-05-01 982 views
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(); 
     } 
     }); 

我的要求是每當用戶點擊下一個按鈕,我需要顯示單選按鈕作爲選項沒有選擇。如果用戶點擊一個選項,他點擊下一個按鈕,然後無論他點擊(選中)自動下一次,在此之前,我需要清除單選按鈕在RadioGroup中對於我有什麼做的......提前如何取消選中Android中的單選按鈕(在radiogroup中)?

謝謝.......

+0

發生了什麼當你使用上面的代碼?你面臨的問題是什麼? – Pragnani 2013-05-01 08:04:10

+0

嘗試將RadioGroup組定義爲類成員,而不是onCreate(); – 2013-05-01 08:08:14

+0

請顯示您的xml代碼。 – 2013-05-01 08:20:05

回答

7

也有您在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(); 
相關問題