【发布时间】:2011-07-17 19:43:02
【问题描述】:
我有一个 ListActivity,列表中的每一行都包含 2 个 TextViews 和 4 个 RadioButtons。
这 2 个 TextView 由 SimpleCursorAdapter 从我的数据库中的表中提取数据填充,而 4 个 RadioButton 只是放入 xml 代码中(它们的 id 被分配给 Java 代码中的 4 个 RadioButton 变量。
基本上我想做的是检查每一行中每个单选按钮的状态,以相应地更新我的数据库。
如何访问每一行 RadioButtons 以查看它们是否被选中?
如果这含糊不清,我深表歉意,如果需要,我会尝试添加更多细节。
非常感谢。
private void processAttendance(){
int index = 0;
this.allStudentsCursor = mDbHelper.fetchEnrolledStudents(mRowId);
lvList=(ListView)findViewById(android.R.id.list);
this.allStudentsCursor.moveToFirst();
while (allStudentsCursor.isAfterLast() == false) {
this.radGroup = (RadioGroup) lvList.getChildAt(index).findViewById(R.id.attendanceGroup);
this.mAttended = (RadioButton)lvList.getChildAt(index).findViewById(R.id.presentRadio);
this.mLate = (RadioButton)lvList.getChildAt(index).findViewById(R.id.lateRadio);
this.mExcused = (RadioButton)lvList.getChildAt(index).findViewById(R.id.excusedRadio);
this.mMissed = (RadioButton)lvList.getChildAt(index).findViewById(R.id.absentRadio);
this.mStudentId = allStudentsCursor.getLong(allStudentsCursor.getColumnIndexOrThrow("_id"));
this.mResult = "";
if(mAttended.isChecked()){
this.mResult ="attended";
radGroup.clearCheck();
}
else if(mExcused.isChecked()){
this.mResult ="excused";
}
else if(mMissed.isChecked()){
this.mResult ="missed";
}
else {
this.mResult ="late";
}
Calendar cal = Calendar.getInstance();
SimpleDateFormat dateFormat = new SimpleDateFormat("MM-dd-yyyy");
String date = dateFormat.format(cal.getTime());
this.mDbHelper.addAttendance(date, this.mResult, this.mStudentId, mRowId);
allStudentsCursor.moveToNext();
index++;
}
finish();
}
【问题讨论】:
标签: android listview android-activity radio-button loops