public boolean validateAndUpdateState ( ) { boolean validationPassed = true ; List < Fragment > fragments = getRetainedChildFragmentManager ( ) . getFragments ( ) ; for ( Fragment fragment : fragments ) { SurveyQuestionView surveyQuestionView = ( SurveyQuestionView ) fragment ; answers . put ( surveyQuestionView . getQuestionId ( ) , surveyQuestionView . getAnswer ( ) ) ; boolean isValid = surveyQuestionView . isValid ( ) ; surveyQuestionView . updateValidationState ( isValid ) ; if ( ! isValid ) { validationPassed = false ; } } return validationPassed ; }
Run this when the user hits the send button and only send if it returns true . This method will update the visual validation state of all questions and update the answers instance variable with the latest answer state .