android - 在完成所有验证之前如何防止导航?
问题描述
我想在我的表单中添加验证。但是有一个问题我按下提交按钮它会快速显示验证,并将空白表单提交给recyclerview。如果你有,请给我解决方案。
解决方案
/**
* Performs action to submit the form if all the validations are fulfilled
*/
public void submitForm() {
if (validateFields()) {
//Todo add your form submission code here
}
}
/**
* Validate all the fields present in the form according to the requirements
* Returns true if there is no validation error, false otherwise.
*/
public boolean validateFields() {
if (editTextEmail.getText().toString().isEmpty()) {
//Show toast or snackbar for validation failed
return false;
} else if (//todo another validation code)
{
//Show toast or snackbar for validation failed
return false;
}
return true;
}
推荐阅读
- java - 如何将带有模块的项目导入另一个项目,而不会丢失我的封装?
- reactjs - Is there anything like Material-UI Autocomplete freeSolo in the React-Admin AutocompleteInput
- sql - 在 azure devops 管道中部署 SQL 时面临错误
- javascript - 我如何将对象键名指定为与其值相同的名称?
- elasticsearch - 我怎样才能让 ElasticSearch 只产生一个字段的前几个单词?
- unit-testing - LiveData 单元测试在协程和多线程下未通过,因为返回 true 而不是预期的 false
- python-3.x - 使用python的浅层CNN模型
- php - 如何在 woocommerce 产品循环(商店页面)中添加减少按钮?
- php - 在 Laravel 的另一个表中保存输入字段
- regex - 使用 C++ 用正则表达式替换子字符串匹配