2011-10-23 9 views
0

ダイナミックに作成されたすべてのラジオボタンを1つのグループにグループ化するにはどうすればよいですか?Android TableLayoutグループダイナミックラジオボタン

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> 

答えて

0

それらはRadioGroupレイアウトに配置する必要がグループとしてラジオボタンを処理します。代わりに別の表のセルにラジオボタンを配置する場合は、グループの動作を自分で実装する必要があります。

RadioButton.SetOnCheckedChangeListener()を使用すると、チェックされたイベントに応答するリスナーを登録できます。

RadioGroup source codeを見ると、これがRadioGroupレイアウトでどのように行われているかを確認できます。