Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I uncheck or reset the radio button?

I am developing an quiz based app. There will be 1 question and 4 option (radio buttons) when user opens this app radio button will be unchecked but the problem comes when the user answers 1 quest and when he goes for next quest radio button will be checked. I want to uncheck/reset the radio buttons for every question. How can I do it?

  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               }              }); 

Logcat

     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)                    

I try like this, but I can't uncheck..

like image 877
Make it Simple Avatar asked Apr 11 '13 09:04

Make it Simple


People also ask

How do you uncheck a radio button?

To set a radio button to checked/unchecked, select the element and set its checked property to true or false , e.g. myRadio. checked = true .

Can you uncheck radio button Android?

You can't uncheck a checked RadioButton. The only way to uncheck is to select some other RadioButton belonging to that RadioGroup. Usually, RadioButtons are used to take mandatory inputs where the user has to choose something and can't leave that field unchecked.

How do I uncheck radio button in React?

To uncheck radio buttons in React, we can set the checked prop of the radio button to false . We have the checked state that we use to set the checked prop of each radio button. Then we set onChange to the changeRadio function.


1 Answers

Put all your buttons in a RadioGroup then when you need to clear them all use RadioGroup.clearCheck();

like image 128
Alexander Kulyakhtin Avatar answered Sep 22 '22 15:09

Alexander Kulyakhtin