0

我在每个线性布局中动态创建了线性布局和单选按钮......但我想对这些单选按钮进行分组,但我无法做到这一点......

LinearLayout linearlayout = (LinearLayout) findViewById(R.id.player_point_entry);

    TextView[] TVplayer = new TextView[number_of_player];
    EditText[] ETpoint = new EditText[number_of_player];
    EditText[] ETmaal = new EditText[number_of_player];
    RadioButton[] won = new RadioButton[number_of_player];
    RadioGroup RG_won = new RadioGroup(this);

    LinearLayout[] dyn_linearLayout = new LinearLayout[number_of_player];

    for(int i =0; i<number_of_player; i++)
    {
        dyn_linearLayout[i] = new LinearLayout(this);
        dyn_linearLayout[i].setPadding(5, 5, 5, 5);
        dyn_linearLayout[i].setOrientation(LinearLayout.HORIZONTAL);
        dyn_linearLayout[i].setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

            TVplayer[i] = new TextView(this);
                TVplayer[i].setText(player_name[i]);
                TVplayer[i].setTypeface(face);
                TVplayer[i].setTextSize(15);
                TVplayer[i].setTextColor(Color.BLACK);
                TVplayer[i].setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1f));

            ETpoint[i] = new EditText(this);
                ETpoint[i].setHint("Point");
                ETpoint[i].setLayoutParams(new LinearLayout.LayoutParams(70, LayoutParams.WRAP_CONTENT, 1f));

            ETmaal[i] = new EditText(this);
                ETmaal[i].setHint("Maal");
                ETmaal[i].setLayoutParams(new LinearLayout.LayoutParams(70, LayoutParams.WRAP_CONTENT, 1f));

            won[i] = new RadioButton(this);
                won[i].setChecked(true);
                won[i].setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
                won[i].setChecked(false);

            dyn_linearLayout[i].addView(TVplayer[i]);
            dyn_linearLayout[i].addView(ETpoint[i]);
            dyn_linearLayout[i].addView(ETmaal[i]);
            dyn_linearLayout[i].addView(won[i]);

            linearlayout.addView(dyn_linearLayout[i]);

    }

请帮帮我...上面的代码让我可以将 RadioButton 添加到不同的 LinearLayout 但可以对它们进行分组...

提前致谢

4

1 回答 1

0

您可以通过编程方式设置 RadioGroup。查看这个问题:以编程方式设置 RadioGroup

于 2012-10-09T15:47:26.103 回答