我得到它的工作。如果有其他人有這個問題,以供將來參考,你必須讓radiogroup成爲孩子,然後在其中工作以獲得按鈕。
這裏是我在我的主XML文件中描述的表
<ScrollView
android:id="@+id/scroll03"
android:layout_width="fill_parent"
android:layout_height="175dp">
<TableLayout
android:id="@+id/TableLayout03"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</TableLayout>
</ScrollView>
然後,我有這個作爲行條目的XML文件:
<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:id="@+id/radioGroup1_lbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:typeface="monospace" />
<RadioGroup
android:id="@+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="175dp">
</RadioGroup>
</TableRow>
這裏是代碼的子集從數據庫創建表格行和廣播組
// Set up the user traits
cmd = String.format("select evaluation_trait_table.trait_name, evaluation_trait_table.id_traitid, " +
"custom_evaluation_name_table.custom_eval_number " +
"from evaluation_trait_table inner join last_eval_table on " +
" evaluation_trait_table.id_traitid = last_eval_table.id_traitid" +
" inner join custom_evaluation_name_table on evaluation_trait_table.id_traitid = " +
" custom_evaluation_name_table.id_traitid where evaluation_trait_table.trait_type = 3 ") ;
crsr = dbh.exec(cmd);
cursor = (Cursor) crsr;
startManagingCursor(cursor);
nRecs3 = cursor.getCount(); // number of user defined traits to use
dbh.moveToFirstRecord();
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()){
user_evaluation_traits.add(cursor.getString(0));
user_trait_numbers.add(cursor.getInt(1));
user_trait_number_items.add(cursor.getInt(2));
}
inflater = getLayoutInflater();
TableLayout table = (TableLayout) findViewById(R.id.TableLayout03);
for(int ii = 0; ii < nRecs3; ii++){
TableRow row = (TableRow)inflater.inflate(R.layout.eval_custom_item, table, false);
tempLabel = user_evaluation_traits.get(ii);
// Set the text for the radiogroup label
((TextView)row.findViewById(R.id.radioGroup1_lbl)).setText(tempLabel);
// Get the text for the buttons
tempText = String.valueOf(user_trait_numbers.get(ii));
cmd = String.format("select custom_evaluation_traits_table.custom_evaluation_item " +
" from custom_evaluation_traits_table " +
" where custom_evaluation_traits_table.id_traitid = '%s' "+
" order by custom_evaluation_traits_table.custom_evaluation_order ASC ", tempText);
crsr = dbh.exec(cmd);
cursor = (Cursor) crsr;
startManagingCursor(cursor);
nRecs4 = cursor.getCount();
dbh.moveToFirstRecord();
ArrayList buttons = new ArrayList();
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()){
buttons.add (cursor.getString(0));
}
radioBtnText = (String[]) buttons.toArray(new String [buttons.size()]);
// Build the radio buttons here
radioGroup = ((RadioGroup) row.findViewById(R.id.radioGroup1));
addRadioButtons(user_trait_number_items.get(ii), radioBtnText);
table.addView(row);
}
這裏是crea TES的RadioGroup中
private void addRadioButtons(int numButtons, String[] radioBtnText) {
int i;
for(i = 0; i < numButtons; i++){
//instantiate...
RadioButton radioBtn = new RadioButton(this);
//set the values that you would otherwise hardcode in the xml...
radioBtn.setLayoutParams
(new LayoutParams
(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
//label the button...
radioBtn.setText(radioBtnText[i]);
Log.i("addradiobuttons", radioBtnText[i]);
radioBtn.setId(i);
//add it to the group.
radioGroup.addView(radioBtn, i);
}
}
和代碼最後的子集,在那裏我居然讀單選按鈕,並準備更新我的數據庫
table = (TableLayout) findViewById(R.id.TableLayout03);
if (nRecs3 != 0) {
for(int ii = 0; ii < nRecs3; ii++){
TableRow row1= (TableRow)table.getChildAt(ii);
tempTrait = user_trait_numbers.get (ii);
RadioGroup rg=(RadioGroup)findViewById(R.id.radioGroup1);
try {
tempRadioBtn = rg.getCheckedRadioButtonId();
cmd = String.format("select custom_evaluation_traits_table.id_custom_traitid " +
" from custom_evaluation_traits_table " +
" where custom_evaluation_traits_table.id_traitid = %s "+
" and custom_evaluation_traits_table.custom_evaluation_order = %s ", tempTrait, tempRadioBtn+1);
crsr = dbh.exec(cmd);
cursor = (Cursor) crsr;
startManagingCursor(cursor);
dbh.moveToFirstRecord();
tempRadioBtn = cursor.getInt(0);
} catch (Exception ex) {
tempRadioBtn = 0;
}
user_scores.add(tempRadioBtn);
}
for(int ii = nRecs3; ii < 5; ii++){
user_scores.add(0);
}
}else {
for(int ii = 0; ii < 5; ii++){
user_scores.add(0);
}
}
// Fill the user score variables from the user_scores array
trait16_data = user_scores.get(0);
trait17_data = user_scores.get(1);
trait18_data = user_scores.get(2);
trait19_data = user_scores.get(3);
trait20_data = user_scores.get(4);
從那裏我建立我的查詢做實際的更新此綿羊記錄在sheep_evaluation_table中。
後從崩潰 – codeMagic
的logcat的我不得不代碼的工作,收集數據,以便回滾到未使用膨脹佈局和硬編碼感興趣的無線電設備組,然後得到而不嘗試使用該子項目。我回來試圖弄清楚多個無線電小組的一般情況。我正在將我的更改再次推進。 – OogieM