How to set radio button checked as default in radiogroup?

前端 未结 8 1590
孤城傲影
孤城傲影 2020-12-23 09:01

I have created RadioGroup and RadioButton dynamically as following:

RadioGroup radioGroup = new RadioGroup(context);
                      


        
8条回答
  •  忘掉有多难
    2020-12-23 09:18

    you should check the radiobutton in the radiogroup like this:

    radiogroup.check(IdOfYourButton)

    Of course you first have to set an Id to your radiobuttons

    EDIT: i forgot, radioButton.getId() works as well, thx Ramesh

    EDIT2:

    android:checkedButton="@+id/my_radiobtn"
    

    works in radiogroup xml

提交回复
热议问题