0

I have developed an quiz based android application in which I'm loading question and answers from an array everything works fine but only issue I'm facing is after selecting an option for a particular question and submitting it the selected option remains selected for the next question also here I need to clear the checked option. Here is what I have tried

    b1.setOnClickListener(new OnClickListener() {

    @Override 
    public void onClick(View v) {

        RadioButton uans = (RadioButton)findViewById(rg1.getCheckedRadioButtonId());
        String ansText = uans.getText().toString();
        //Toast.makeText(getApplicationContext(), ""+ansText, 5000).show();

        if(ansText.equalsIgnoreCase(answers[flag]))
        {

            correct++;
        }
        else
        {
            wrong++;
        }

        //Toast.makeText(getApplicationContext(), "Flag before INCR==> " + flag, 5000).show();

        flag++;


        if(flag < ques.length)
        {
            //Toast.makeText(getApplicationContext(), "Flag after INCR==> " + flag, 5000).show();
            rg1.setEnabled(false);
            t2.setText(ques[flag]);
            r1.setText(options[flag*4]);
            r2.setText(options[flag*4 + 1]);
            r3.setText(options[flag*4 + 2]);
            r4.setText(options[flag*4 + 3]);
        }
MiguelHincapieC
  • 5,445
  • 7
  • 41
  • 72
Sunil
  • 49
  • 1
  • 12

2 Answers2

0

Try uans.setChecked(false); - from your code this is getting the checked radio button from the group (rg1).

Tip: If you need to change the radio button state yourself (such as when loading a saved CheckBoxPreference), use the setChecked(boolean) or toggle() method.

Finn K
  • 620
  • 3
  • 8
0

You can put all your RadioButtons in a RadioGroup then when you move to the next question just clear them all with clearCheck() method (RadioGroup.clearCheck();)

Rami
  • 7,879
  • 12
  • 36
  • 66