I have TextInputLayout in login, when i click on login button if username is empty then show error same as with password when password is empty then show error but if username is empty and password is non empty at that time error is not shown so how can i solve this problem? My Code is like below!!!
@Override
public void onClick(View v) {
Intent mIntent;
switch (v.getId()) {
case R.id.txtSignIn:
hideKeyboard(mActivity, v);
if (etUserName.getText().toString().equals("")) {
etUserName.requestFocus();
etUserName.setCursorVisible(true);
tilPassword.setErrorEnabled(false);
tilUserName.setErrorEnabled(true);
tilUserName.setError(getString(R.string.username_required));
} else if (etPassword.getText().toString().equals("")) {
etPassword.requestFocus();
etPassword.setCursorVisible(true);
tilUserName.setErrorEnabled(false);
tilPassword.setErrorEnabled(true);
tilPassword.setError(getString(R.string.password_required));
} else {
tilUserName.setErrorEnabled(false);
tilPassword.setErrorEnabled(false);
showToast(mActivity, getString(R.string.successfully_login), 0);
mIntent = new Intent(SignIn.this, DashBoard.class);
startActivity(mIntent);
}
break;
case R.id.txtSignUp:
mIntent = new Intent(mActivity, SignUp.class);
startActivity(mIntent);
break;
case R.id.txtForgotPassword:
mIntent = new Intent(mActivity, ForgotPassword.class);
startActivity(mIntent);
break;
}
try {
} catch (Exception e) {
LOGD(getClass().getSimpleName(), e.getMessage());
LOGE(getClass().getSimpleName(), e.getMessage());
}
}