请参阅以下代码:
for(Form form:formBody){
switch (Integer.parseInt(form.getFieldType())) {
case 8:
showDateTimePicker(form);
break;
case 3:
showSingleTextBox(form);
break;
case 9:
showRadioButtonWithQuestion(form);
break;
case 2:
showSingleTextBox(form);
break;
case 4:
showTwoRadioButtons(form);
break;
case 6:
showRadioButtonsForRating(form);
break;
case 7:
showRadioButtonsForRating(form);
break;
case 10:
showSingleTextBox(form);
break;
case 15:
showRadioButtonWithQuestion(form);
break;
case 17:
showThreeCheckboxesWithThreeRadioButtons(form);
break;
case 18:
show12TextBoxesWithThreeRadioButton(form);
break;
case 19:
showOneEditTextWithThreeRadioButtonAndThreeEditText(form);
break;
case 20:
threeCheckboxWithQuestion(form);
break;
}
}
(请参阅上面的代码) 所以如上所述,我在android LinearLayout(VERTICAL)中动态添加视图,并且它的工作非常好。但我遇到的问题是在用户点击“保存”按钮后获取值。我如何获得每个editText /复选框等的值?
答案 0 :(得分:1)
从下面的线性布局中获取子视图计数,
int childcount = linearlayout.getChildCount();
根据子位置,您可以获取视图和查看属性,
for (int i=0; i < childcount; i++){
View v = ll.getChildAt(i);
EditText editText= (EditText) v;
//get the text form edittext or checkbox here
}