我正在做一个测验应用程序我有一个带有 4 个单选按钮的单选组,我有一个下一步按钮。
在显示第一个问题并回答检查时没有问题..当用户给出下一个时,单选组应取消选中。如何实施?
当用户选择该选项时,它应该验证答案是否正确。我已将正确答案存储在数组中。当用户切换选项时,它会在切换按钮中显示错误。如何实施?
btn_practicerg.setOnCheckedChangeListener(new OnCheckedChangeListener(){ @Override public void onCheckedChanged(RadioGroup group, int checkedId) { RadioButton radioButton = (RadioButton)group. findViewById(checkedId); 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; } crrtans=new ArrayList<String>(new ArrayList<String>(crrtans)); if (temp.equals(crrtans.get(l))){ TextView txtRadio = (TextView) findViewById(R.id.rdtxt); txtRadio.setText("" + radioButton.getText() + " IS CORRECT"); txtRadio.setTextColor(Color.parseColor("#008000")); }else{ TextView txtRadio = (TextView) findViewById(R.id.rdtxt); txtRadio.setText("" + radioButton.getText() + "is INCORRECT"); txtRadio.setTextColor(Color.parseColor("#FF0000")); } } }); Button nextBtn = (Button) findViewById(R.id.nxt_btn); nextBtn.setOnClickListener(new Button.OnClickListener(){ public void onClick(View v){ if (j == ques1.size() -1) { showAlert1(); } else{ ++j; ++num; TextView txtque = (TextView) findViewById(R.id.que_txt); txtque.setText("Q" + num +ques1.get(j)); } });