简体   繁体   English

使用以下命令检查EditText值

[英]Check EditText value with

I am trying to do this, users are signing up, and for the password field I don't want to have two password fields (like traditionally password and the other is for confirm password) I want to have only one edittext and when after entering the password for first time and loose focus, well the below code is self-explanatory 我正在尝试执行此操作,用户正在注册,并且对于密码字段,我不想有两个密码字段(传统上是密码,另一个是用于确认密码),我只希望有一个edittext,输入后第一次输入密码并没有重点,下面的代码是不言自明的

passwordSgnup_et.setOnFocusChangeListener(new View.OnFocusChangeListener() {
                    @Override
                    public void onFocusChange(View v, boolean hasFocus) {
                        if(!hasFocus ) {
                            if (i <= 0) {
                                passwordSgnup_et.requestFocus();
                                cfmPasswordSgnup = Password;
                                passwordSgnup_et.getText().clear();
                                passwordSgnup_et.setHint("Confirm Password");
                                if (passwordSgnup_et.getText().toString() .equals( cfmPasswordSgnup)) {
                                    ParseUser userSignup = new ParseUser();
                                    userSignup.setUsername(Name);
                                    userSignup.setEmail(Email);
                                    userSignup.setPassword(Password);
                                    userSignup.put("Nickname",nickName);

Problem that I am facing is this. 我面临的问题是这个。 How can I know if the confirm password is entered and matches with the one entered the first time. 我如何知道是否输入了确认密码并与第一次输入的密码相匹配。 I am confused there. 我很困惑。 Also to exit after the confirm password matches with the first password I am using the good old int i <= 0 logic anyway to improve this? 在确认密码与第一个密码匹配后也要退出我正在使用旧的int i <= 0逻辑来改善这一点吗?

EDIT: This question was closed as a duplicate simply referring to another equals to question, MY QUESTION being is that, in the logic you can see that, 编辑:这个问题被关闭了,只是一个重复,简单地提到另一个等于问题,我的问题是,在逻辑上您可以看到,

passwordSgnup_et.setHint("Confirm Password");
                                    if (passwordSgnup_et.getText().toString() .equals( cfmPasswordSgnup)) {

in between these two lines i need to take in the userinput (confirmpassword) to actually compare with the first password, that is what I am not able to get it. 在这两行之间,我需要输入userinput(确认密码)以与第一个密码进行实际比较,这是我无法获得的。

One workaround taking a example with just one edittext 一种解决方法仅用一个edittext作为示例

String password = null;
edittext.setOnFocusChangeListener(new View.OnFocusChangeListener() {
    @Override
    public void onFocusChange(View v, boolean hasFocus) {
        //First time edittext will be with default initialization so no tag will be set so u can check 
        if (!hasFocus){
            if (v.getTag() == null){
                //you require to put validations you want
                password = edittext.getText().toString();
                v.setTag("c");
                v.setText("");
                v.setHint("Confirm Password");
                v.requestFocus();
            }else if (((String)v.getTag()).equals("c"){
                //It is now confirm password field lost focus
            }
        }
    }
});

apart from this you can also implement the textwatcher and in afterTextChanged you can check 除此之外,您还可以实现textwatcher,在afterTextChanged中可以检查

if (((String)v.getTag()).equals("c") {
   // So user has completed entering confirm password so you can put a check. 
}

I have not tested this code so it might have some code level issues/warning which you require to fix in actual implementation. 我尚未测试此代码,因此它可能存在一些代码级问题/警告,您需要在实际实现中解决这些问题/警告。

I think you want to use a TextWatcher . 我认为您想使用TextWatcher

TextView.addTextWatcher(...)

There are callbacks to get the info about when input is done. 有一些回调可获取有关何时完成输入的信息。 And check out OnFocusChangeListener interface as well! 并查看OnFocusChangeListener接口!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM