我正在开发一个基于测验的应用程序。当用户打开此应用程序时,将有 1 个问题和 4 个选项(单选按钮)单选按钮将被取消选中,但当用户回答 1 个任务并且当他进行下一个任务时,将选中单选按钮。我想取消选中/重置每个问题的单选按钮。我该怎么做?
answ1=new ArrayList<String>(new ArrayList<String>(answ1));
btn_practice1.setText(answ1.get(0));
btn_practice2.setText(answ1.get(1));
btn_practice3.setText(answ1.get(2));
btn_practice4.setText(answ1.get(3));
btn_practicerg.setOnCheckedChangeListener(new OnCheckedChangeListener(){
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
RadioButton radioButton = (RadioButton)group. findViewById(checkedId); //line 262
String temp = radioButton.getText().toString();
switch(btn_practicerg.getCheckedRadioButtonId()){
case R.id.RB1:
if (btn_practice1.isChecked()){
btn_practice2.setChecked(false);
btn_practice3.setChecked(false);
btn_practice4.setChecked(false);
}
break;
case R.id.RB2:
if (btn_practice2.isChecked()){
btn_practice1.setChecked(false);
btn_practice3.setChecked(false);
btn_practice4.setChecked(false);
}
break;
case R.id.RB3:
if (btn_practice3.isChecked()){
btn_practice1.setChecked(false);
btn_practice2.setChecked(false);
btn_practice4.setChecked(false);
}
break;
case R.id.RB4:
if (btn_practice4.isChecked()){
btn_practice1.setChecked(false);
btn_practice2.setChecked(false);
btn_practice3.setChecked(false);
}
break;
default:
btn_practice1.setChecked(false);
btn_practice2.setChecked(false);
btn_practice3.setChecked(false);
btn_practice4.setChecked(false);
}
ImageView nextBtn = (ImageView) findViewById(R.id.nxt_btn);
nextBtn.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v){
btn_practicerg.clearCheck(); //line 355
}
});
日志猫
E/AndroidRuntime(729):at
com.example.TEENEINSTIEN.Question$LoadQuestions$2.onCheckedChanged(Question.java:262)
E/AndroidRuntime(729):at android.widget.RadioGroup.setCheckedId(RadioGroup.java:172)
E/AndroidRuntime(729):at android.widget.RadioGroup.check(RadioGroup.java:166)
E/AndroidRuntime(729):at android.widget.RadioGroup.clearCheck(RadioGroup.java:205)
E/AndroidRuntime(729):at
com.example.TEENEINSTIEN.Question$LoadQuestions$3.onClick(Question.java:355)
E/AndroidRuntime(729):at android.view.View.performClick(View.java:2485)
E/AndroidRuntime(729):at android.view.View$PerformClick.run(View.java:9080)
我尝试这样,但我无法取消选中..