2013-05-01 986 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(); 
相关问题