Skip to content

09 Validating a dialog's content

Michael Rapp edited this page Dec 27, 2017 · 1 revision

It is also possible to validate a dialog's content when its positive button is clicked by the user. Therfore the interface DialogValidator has to be implemented. It defines the method validate(AbstractValidateableDialog):boolean, which has to be overridden in order to return, whether the dialog's content is valid, or not. Multiple instances of this interface can be added to one single instance of the class MaterialDialog.Builder by using either one of the following methods:

addValidator(DialogValidator):Builder
addAllValidators(Collection):Builder

Previously added listener instances can be removed afterwards by using one of the methods below:

removeValidator(DialogValidator):Builder
removeAllValidators(Collection):Builder

When the dialog's positive button is clicked by the user, all added validators will be executed. If one of them returns false from its validate-method, the dialog will not be dismissed. When the negative or neutral button is clicked instead, no validation will be performed.