How to set radio button checked as default in radiogroup?

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

I have created RadioGroup and RadioButton dynamically as following:

RadioGroup radioGroup = new RadioGroup(context);
                      


        
相关标签:
8条回答
  • 2020-12-23 09:19
    RadioGroup radioGroup = new RadioGroup(context);
    RadioButton radioBtn1 = new RadioButton(context);
    RadioButton radioBtn2 = new RadioButton(context);
    RadioButton radioBtn3 = new RadioButton(context);
    
    radioBtn1.setText("Less");
    radioBtn2.setText("Normal");
    radioBtn3.setText("More");
    
    radioGroup.addView(radioBtn1);
    radioGroup.addView(radioBtn2);
    radioGroup.addView(radioBtn3);
    radioBtn2.setChecked(true);
    
    0 讨论(0)
  • 2020-12-23 09:31
        RadioGroup radioGroup = new RadioGroup(WvActivity.this);
        RadioButton radioBtn1 = new RadioButton(this);
        RadioButton radioBtn2 = new RadioButton(this);
        RadioButton radioBtn3 = new RadioButton(this);
    
        radioBtn1.setText("Less");
        radioBtn2.setText("Normal");
        radioBtn3.setText("More");
    
    
        radioGroup.addView(radioBtn1);
        radioGroup.addView(radioBtn2);
        radioGroup.addView(radioBtn3);
    
        radioGroup.check(radioBtn2.getId());
    
    0 讨论(0)
提交回复
热议问题