Skip to content
This repository was archived by the owner on Nov 5, 2025. It is now read-only.

Commit c6adada

Browse files
committed
Add code of validation listener on README
1 parent 4eb0f3f commit c6adada

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,41 @@ protected void onCreate(Bundle savedInstanceState) {
150150
}
151151
```
152152

153+
Or you can use `toValidate()` if prefer using listener to validation response:
154+
155+
```
156+
public class YourActivity extends AppCompatActivity implements Validator.ValidationListener {
157+
158+
...
159+
160+
@Override
161+
protected void onCreate(Bundle savedInstanceState) {
162+
super.onCreate(savedInstanceState);
163+
164+
MainActivityBinding binding = DataBindingUtil.setContentView(this, R.layout.main_activity);
165+
final Validator validator = new Validator(binding);
166+
validator.setValidationListener(this);
167+
168+
binding.validate.setOnClickListener(new View.OnClickListener() {
169+
@Override
170+
public void onClick(View v) {
171+
validator.toValidate()
172+
}
173+
});
174+
}
175+
176+
@Override
177+
public void onSuccess() {
178+
saveToDatabase();
179+
}
180+
181+
@Override
182+
public void onError() {
183+
Toast.makeText(YourActivity.this, "Dados inválidos!", Toast.LENGTH_SHORT).show();
184+
}
185+
}
186+
```
187+
153188
### Custom Error Messages ###
154189

155190
You can add custom error messages by using the same validation rule name and adding `Message` at the end, such as `validateTypeMessage`, `validateDateMessage`, `validateRegexMessage` and so on. For example:

0 commit comments

Comments
 (0)