在我的应用程序中,通常会像下面这样显示验证错误信息:
if(someString.equals("")){
editText.setError("UserName Should not be blank");
}
有其他的方法来显示错误消息吗?
我需要你的建议。
if(someString.equals("")){
editText.setError("UserName Should not be blank");
}
有其他的方法来显示错误消息吗?
我需要你的建议。
我认为你展示错误信息的方式比 toast 更好。有时候 toast 的持续时间太短了,用户来不及看到。
你也可以通过这样做来实现:
EditText et11 = (EditText)findViewById(R.id.username);
if(et11.getText().toString().isEmpty())
{
et11.setError("UserName Should not be blank");
}
private EditText edt_firstName;
private String firstName;
firstName = edt_firstName.getText().toString().trim();
private void validateData(){
firstName = edt_firstName.getText().toString().trim();
if (!firstName.isEmpty(){
//here api call for the login or any other...
} else {
if (firstName.isEmpty()) {
edt_firstName.setError("Please Enter First Name");
edt_firstName.requestFocus();
}
}
}