请引用以下代码:
对于(表单表单: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) 中动态添加 View ,并且它工作得很好。但我面临的问题是在用户单击“保存”按钮后获取值。我将如何获取每个 editText/复选框等的值?
最佳答案
从您的线性布局中获取 subview 计数,如下所示,
int childcount = linearlayout.getChildCount();
根据子位置,您可以获得 View 和 View 属性,例如,
for (int i=0; i < childcount; i++){
View v = ll.getChildAt(i);
EditText editText= (EditText) v;
//get the text form edittext or checkbox here
}
关于java - 如何从 android 表单中获取动态添加的 editTexts 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46337708/