2015-05-18 78 views
0

我正在尋找類似的Android相關工具,我可以將表格中的每個單元格添加單選按鈕並獲取它們的位置。有沒有人有過之前的工作,如果你可以分享示例代碼會有幫助。由於在Android中使用Radiobuttons的表格

enter image description here

+0

嘗試這樣http://stackoverflow.com/questions/2361205/how-to-add-a-radio-group -to-單選按鈕-內部-A-表的- –

回答

0

以下僞應該讓你開始:

//create a radio group 

RadioGroup rg = new RadioGroup(context);               
RadioGroup.LayoutParams rgParams = new RadioGroup.LayoutParams(          
          RadioGroup.LayoutParams.WRAP_CONTENT,              
          RadioGroup.LayoutParams.WRAP_CONTENT);              
rg.setLayoutParams(rgParams); 

//add the radio group to the row. 
rowView.addView(rg); 

//add radio buttons 
for (i = 0; i < length; i++) { 

     RadioButton btn = new RadioButton(context); 
     btn.setText(description[i]); 

     //or save an object which will hold all information you need 
     btn.setTag(rowNumber); 
     btn.setOnClickListener(new OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       Log.d(TAG, v.getTag()); 
      } 
     }); 

     if (<some condition>) { 
     btn.setChecked(true); 
     } 

     rg.addView(btn); 
} 
相關問題