How can I uncheck or reset the radio button?

后端 未结 3 848
我在风中等你
我在风中等你 2021-02-11 16:58

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 u

相关标签:
3条回答
  • 2021-02-11 17:38

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

    0 讨论(0)
  • 2021-02-11 17:46

    I think the problem is with btn_practicerg object i.e if you are creating new RadioGroup object everytime you display a new question then you have to execute RadioGroup.clearCheck() on new btn_practicerg object instead of old one that I think you are doing currently.

    Even better:

        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_practice1.setChecked(false);
        btn_practice2.setChecked(false);
        btn_practice3.setChecked(false);
        btn_practice4.setChecked(false);
    

    to uncheck all the buttons in the beginning. I hope this will solve your problem.

    0 讨论(0)
  • 2021-02-11 17:53

    if the Radiobutton belong to a radiogroup you can NEVER unchecked alone that button programaticaly, so you must to do a method to unched all first.

        public void unchecked()
         {
         RadioGroup x=findViewById(R.id.NameOfRadiogroup);
         x.clearCheck();
         }  
    

    and then you must to call the method.

    0 讨论(0)
提交回复
热议问题