private boolean isFieldPresent(FormField formField, ViewGroup parentView) { boolean result = false; int id = formField.id(); // Check if id exists in parent view if (id > 0 && parentView.findViewById(id) != null) { result = true; } return result; }
private void addFormField(FormField formFieldAnnotation, ViewGroup parentView) { Log.i(TAG, "adding form field " + formFieldAnnotation.type()); int layoutResId = GRFormField.getLayoutId(formFieldAnnotation); if (layoutResId > 0) { View view; if (isFieldPresent(formFieldAnnotation, parentView)) { view = parentView.findViewById(formFieldAnnotation.id()); } else { view = activity.getLayoutInflater().inflate(layoutResId, parentView, false); GRFormField.assignViewId(view, formFieldAnnotation); parentView.addView(view); } GRFormField formField = GRFormField.construct(this, formObject, formFieldAnnotation, view); formFieldList.add(formField); } else { Log.w(TAG, "layout for " + formFieldAnnotation.type() + " not found"); } }