我有一個列表視圖與動態單選按鈕(它將創建基於大小的一些問題,在第一個問題我有4個單選按鈕第二個問題可能有3個單選按鈕... ..)。我的問題是當用戶選擇使用單選按鈕的答案我需要提交這些表單。那麼我怎樣才能實現這些列表視圖數據以及選定的答案。我還需要檢查問題是否回答(表示檢查收音機組)。當我提交我想要的整個數據。任何人都可以幫助我。Radiogroup在Android的列表視圖
這是我getview
public View getView(final int position, View convertView, ViewGroup parent) {
View view = convertView;
final ViewHolder viewHolder = new ViewHolder();
view = View.inflate(mContext, R.layout.item_list_bradenscale_entry, null);
viewHolder.txtQuestionHeadName = (TextView) view.findViewById(R.id.textview_question_name);
viewHolder.radioGroup = (RadioGroup) view.findViewById(R.id.radio_group);
viewHolder.radioButtonOption1 = (RadioButton) view.findViewById(R.id.radio1);
viewHolder.radioButtonOption2 = (RadioButton) view.findViewById(R.id.radio2);
viewHolder.radioButtonOption3 = (RadioButton) view.findViewById(R.id.radio3);
viewHolder.radioButtonOption4 = (RadioButton) view.findViewById(R.id.radio4);
viewHolder.txtQuestionHeadHint = (TextView) view.findViewById(R.id.textview_question_hint);
viewHolder.txtOption1Hint = (TextView) view.findViewById(R.id.textview_option1Hint);
viewHolder.txtOption2Hint = (TextView) view.findViewById(R.id.textview_option2Hint);
viewHolder.txtOption3Hint = (TextView) view.findViewById(R.id.textview_option3Hint);
viewHolder.txtOption4Hint = (TextView) view.findViewById(R.id.textview_option4Hint);
view.setTag(viewHolder);
selectedList = new
final DataContractQuestionList myDataitem = arrData.get(position);
viewHolder.txtQuestionHeadName.setText(myDataitem.QuestionTitle);
viewHolder.txtQuestionHeadHint.setText(myDataitem.QuestionHint);
viewHolder.radioButtonOption1.setText(myDataitem.QuestionOptions.get(0).OptionTitle);
viewHolder.radioButtonOption2.setText(myDataitem.QuestionOptions.get(1).OptionTitle);
viewHolder.radioButtonOption3.setText(myDataitem.QuestionOptions.get(2).OptionTitle);
viewHolder.txtOption1Hint.setText(myDataitem.QuestionOptions.get(0).OptionHint);
viewHolder.txtOption2Hint.setText(myDataitem.QuestionOptions.get(1).OptionHint);
viewHolder.txtOption3Hint.setText(myDataitem.QuestionOptions.get(2).OptionHint);
if (myDataitem.QuestionOptions.size() < 4) {
viewHolder.radioButtonOption4.setVisibility(View.INVISIBLE);
viewHolder.txtOption4Hint.setVisibility(View.INVISIBLE);
} else {
viewHolder.radioButtonOption4.setText(myDataitem.QuestionOptions.get(3).OptionTitle);
viewHolder.txtOption4Hint.setText(myDataitem.QuestionOptions.get(3).OptionHint);
viewHolder.radioButtonOption4.setChecked(myDataitem.QuestionOptions.get(3).checkedStatus);
}
viewHolder.radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
int selectedRadioButton = group.getCheckedRadioButtonId();
View radioButton = group.findViewById(selectedRadioButton);
int radioId = group.indexOfChild(radioButton);
if (radioId/2 == 0) {
viewHolder.radioButtonOption1.setChecked(true);
myDataitem.QuestionOptions.get(0).checkedStatus = true;
myDataitem.QuestionOptions.get(1).checkedStatus = false;
myDataitem.QuestionOptions.get(2).checkedStatus = false;
if (myDataitem.QuestionOptions.size() == 4) {
myDataitem.QuestionOptions.get(3).checkedStatus = false;
}
} else if (radioId/2 == 1) {
viewHolder.radioButtonOption2.setChecked(true);
myDataitem.QuestionOptions.get(0).checkedStatus = false;
myDataitem.QuestionOptions.get(1).checkedStatus = true;
myDataitem.QuestionOptions.get(2).checkedStatus = false;
if (myDataitem.QuestionOptions.size() == 4) {
myDataitem.QuestionOptions.get(3).checkedStatus = false;
}
} else if (radioId/2 == 2) {
viewHolder.radioButtonOption3.setChecked(true);
myDataitem.QuestionOptions.get(0).checkedStatus = false;
myDataitem.QuestionOptions.get(1).checkedStatus = false;
myDataitem.QuestionOptions.get(2).checkedStatus = true;
if (myDataitem.QuestionOptions.size() == 4) {
myDataitem.QuestionOptions.get(3).checkedStatus = false;
}
} else if (radioId/2 == 3) {
if (myDataitem.QuestionOptions.size() == 4) {
viewHolder.radioButtonOption4.setChecked(true);
myDataitem.QuestionOptions.get(0).checkedStatus = false;
myDataitem.QuestionOptions.get(1).checkedStatus = false;
myDataitem.QuestionOptions.get(2).checkedStatus = false;
myDataitem.QuestionOptions.get(3).checkedStatus = true;
}
}
}
});
viewHolder.radioButtonOption1.setChecked(myDataitem.QuestionOptions.get(0).checkedStatus);
viewHolder.radioButtonOption2.setChecked(myDataitem.QuestionOptions.get(1).checkedStatus);
viewHolder.radioButtonOption3.setChecked(myDataitem.QuestionOptions.get(2).checkedStatus);
return view;
}
使用相同的數組來存儲選定的狀態。然後根據狀態,您可以獲取檢查的數據併發送。 –
發表我的getview() – Sri