2011-12-13 5 views
0

라디오 그룹에 라디오 버튼을 동적으로 추가하여 테이블 레이아웃을 만들고 라디오 그룹을 포함하는 행을 선택했는지 확인하려는 경우 동일한 행에서도 texview 데이터를 다시 검색하려고합니다. . 내가 할 수있는 모든 제안은 나를 위해 큰 도움이 될 것입니다.scrollview에서 테이블 행 선택 오류

public class TabActivity extends Activity { 
TableLayout table; 
RadioGroup mRadioGroup; 
ArrayList<String> list_name; 

int color_blue = -16776961; 
int color_gray = -7829368; 
int color_black = -16777216; 
int color_white = -1; 

final int CHECK_BUTTON_ID = 982301; 
int ids_check[]; 
boolean bool_check[]; 


/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    table = (TableLayout) findViewById(R.id.tableLayout1); 

    list_name = new ArrayList<String>(); 

    list_name.add("Close"); 
    list_name.add("Cristiano"); 
    list_name.add("David"); 
    list_name.add("Fernando"); 
    list_name.add("Messi"); 
    list_name.add("Kaka"); 
    list_name.add("Wayne"); 

    list_name.add("use"); 
    list_name.add("e"); 
    list_name.add("eff"); 
    list_name.add("euyr"); 
    list_name.add("ejjyytuty"); 
    list_name.add("madre"); 
    list_name.add("yuir"); 
    list_name.add("eyrty"); 
    list_name.add("etytr"); 
    list_name.add("ewrrtt"); 

    bool_check = new boolean[list_name.size()]; 
    ids_check = new int[list_name.size()]; 
    createTableRows(); 

    } 

    public void createTableRows() 
    { 
    for (int i = 0; i < list_name.size(); i++) 
    { 
    final TableRow table_row = new TableRow(this); 
    TextView tv_name = new TextView(this); 
    Button btn_check = new Button(this); 
    ImageView img_line = new ImageView(this); 

    table_row.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); 
    table_row.setBackgroundColor(color_black); 
    table_row.setGravity(Gravity.CENTER_HORIZONTAL); 
    // table_row.setFocusable(true); 

    mRadioGroup = new RadioGroup(this); 

    // test adding a radio button programmatically 

    final RadioButton[] mbutton=new RadioButton[7]; 
    for(int l=0;l<7;l++){ 
     mbutton[l]=new RadioButton(this); 
     mbutton[l].setText("test"+l); 
     mRadioGroup.addView(mbutton[l]); 

    } 


// LinearLayout.LayoutParams layoutParams = new RadioGroup.LayoutParams(
      // RadioGroup.LayoutParams.WRAP_CONTENT, 
      // RadioGroup.LayoutParams.WRAP_CONTENT); 
    // mRadioGroup.addView(newRadioButton); 






    tv_name.setText((CharSequence) list_name.get(i)); 
    tv_name.setTextColor(color_blue); 
    tv_name.setTextSize(30); 
    tv_name.setTypeface(Typeface.DEFAULT_BOLD); 
    tv_name.setWidth(150); 

    btn_check.setLayoutParams(new LayoutParams(30, 30)); 
    btn_check.setBackgroundResource(R.drawable.small_checkbox_unchecked); 

    img_line.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, 2)); 
    img_line.setBackgroundResource(R.drawable.separater_line); 

    table_row.addView(tv_name); 
    table_row.addView(btn_check); 
    table_row.addView(mRadioGroup); 
    table.addView(table_row); 
    table.addView(img_line); 
//table.addView(mRadioGroup); 

    mRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { 
     public void onCheckedChanged(RadioGroup mRadioGroup, int checkedId) { 
      for(int i=0; i<mRadioGroup.getChildCount(); i++) { 
       RadioButton btn = (RadioButton) mRadioGroup.getChildAt(i); 
       int t=table.indexOfChild(table_row); 
       System.out.println(t); 
       if(btn.getId() == checkedId) { 
         String text = btn.getText().toString(); 
         // do something with text 
         Log.d(text," event1"); 
         return; 
       } 
      } 
     } 
    }); 



    } 

    } 
    } 
+0

코드에서 작동하지 않는 것은 무엇입니까? 받고있는 오류에 대한 세부 정보를 포함하십시오 (예외가있는 경우 LogCat). – Guillaume

답변

0

왜 ListView를 사용하지 않습니까? 코드에는 목록보기로 수행 할 수없는 것이 없습니까? 사용자 지정 어댑터를 설정하여 레이아웃을 추가 할 수 있습니다.