Java Android TableLayout组动态单选按钮

Java Android TableLayout组动态单选按钮,java,android,Java,Android,如何将所有动态创建的单选按钮分组到一个组中 while (cursor.moveToNext()) { TableRow row = new TableRow(this); // CheckBox chk = new CheckBox(this); RadioButton radioBtn = new RadioButton(this); // chk.setText(cursor.getString(cursor.getColumnIndex("fr

如何将所有动态创建的单选按钮分组到一个组中

while (cursor.moveToNext()) {
    TableRow row = new TableRow(this);
     // CheckBox chk = new CheckBox(this);
      RadioButton  radioBtn =  new RadioButton(this);
     // chk.setText(cursor.getString(cursor.getColumnIndex("from_text")));
      radioBtn.setText(cursor.getString(cursor.getColumnIndex("from_text")));
      radioBtn.
      row.addView(radioBtn);
      table.addView(row);
}
Xml

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />

        <TableLayout
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:id="@+id/myTable"/>         
</LinearLayout>


要将单选按钮作为一个组来处理,必须将它们放置在一个
放射组中。如果要将单选按钮放在单独的表单元格中,则必须自己实现组行为

您可以使用注册响应已检查事件的侦听器

您可以查看以了解如何使用RadioGroup布局完成此操作