将ArrayList值设置为for循环中的RadioButton

MrP*_*cil 0 android arraylist

arrayList [5,8,13,18,19]从服务器获取,我想RadioGroup在xml文件中创建一个.选择可解决的项目后,我会将所选项目放入arrayList并在单击确定按钮后将查询发送到服务器.我怎样才能以编程方式创建RadioGroup

我试过这个,但我不知道如何设置值RadioButtonArrayList值.我怎样才能让tp工作?

private void createRadioButton(final ArrayList<Integer> items) {

    final LinearLayout ll = (LinearLayout) findViewById(R.id.lila);
    final ArrayList<RadioButton> rb = new ArrayList<RadioButton>();
    final RadioGroup rg = new RadioGroup(this); // create the RadioGroup
    rg.setOrientation(RadioGroup.HORIZONTAL);// or RadioGroup.VERTICAL
    for (int i = 0; i < items.size(); i++) {
        items.get(i) = new RadioButton(this);
    }
}
Run Code Online (Sandbox Code Playgroud)

Eri*_*nez 5

试试这个

    final RadioGroup rg = new RadioGroup(this); // create the RadioGroup
    rg.setOrientation(RadioGroup.HORIZONTAL);// or RadioGroup.VERTICAL
    for (int i = 0; i < items.size(); i++) {
        RadioButton rb = new RadioButton(this);
        rb.setText(items.get(i)+"");
        rg.addView(rb);
    }
Run Code Online (Sandbox Code Playgroud)

随着addView您添加动态创建RadioButtonRadioGroup.