我正在尝试检查我的电子邮件是否与电子邮件类型匹配,如果我的密码长度大于0,那么我使用布尔值来检查,但我认为这看起来很糟糕,因为它总是返回false并且不能在这里将我的java代码更改为true:
private boolean mEmail_Correct = false;
private boolean mPass_Correct = false;
mEmail.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {}
@Override
public void afterTextChanged(Editable s) {
if (android.util.Patterns.EMAIL_ADDRESS.matcher(s.toString()).matches()){mEmail_Correct = true;}
else {mEmail_Correct = false;}}});
mPassword.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {}
@Override
public void afterTextChanged(Editable s) {
if (s.lenght>0){mPass_Correct = true;}
else {mPass_Correct = false;}}});
if (mEmail_Correct && mPass_Correct){}//I need to make sign in btn light
else {}//I need to make sign in btn dim/faint
//But nothing happen so what can i use instead of private booleans
两个布尔值都返回false所以有没有办法将布尔值更改为true我认为mEmail_Correct = true;不能正常工作。
答案 0 :(得分:0)
如果用户正确输入电子邮件和密码,您可以根据用户触发执行所需工作的功能
private boolean mEmail_Correct = false;
private boolean mPass_Correct = false;
mEmail.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {}
@Override
public void afterTextChanged(Editable s) {
if (android.util.Patterns.EMAIL_ADDRESS.matcher(s.toString()).matches()){emailWrittenCorrect(true);}
else {emailWrittenCorrect(false);}}});
mPassword.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {}
@Override
public void afterTextChanged(Editable s) {
if (s.lenght>0){passwordWrittenCorrect(true);}
else {passwordWrittenCorrect(false);}}});
private passwordWrittenCorrect(boolean x){
passwordEmailCheck(null,x);
}
private void emailWrittenCorrect(boolean x){
passwordEmailCheck(x,null);
}
private passwordEmailCheck(boolean emailStat, boolean passwordStat){
if(emailStat!=null){
mEmail_Correct = emailStat;
}
if(passwordStat!=null){
mPass_Correct = passwordStat
}
if(emailStat && passwordStat){
//show button
}
}