2011-10-23 2 views
0

어떻게 동적으로 생성 된 모든 radioButton을 하나의 그룹으로 그룹화 할 수 있습니까?안드로이드 TableLayout 그룹 dynamic radioButtons

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 레이아웃이 어떻게 수행되는지 확인할 수 있습니다.