How to add radio button dynamically as per the given number of counts?

前端 未结 4 807
心在旅途
心在旅途 2020-12-01 03:28

I have tried this code..It will display three radio buttons in a single row when the emulator starts. But I need a button event for this. i.e; if I click the button, it shou

4条回答
  •  广开言路
    2020-12-01 04:24

    Try something like below:

    RadioGroup rgp= (RadioGroup) findViewById(R.id.radiogroup);
    RadioGroup.LayoutParams rprms;
    
    for(int i=0;i<3;i++){
          RadioButton radioButton = new RadioButton(this);
          radioButton.setText("new"+i);
          radioButton.setId(View.generateViewId());
          rprms= new RadioGroup.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
          rgp.addView(radioButton, rprms);
    }
    

提交回复
热议问题