用户输入最后一位数字后立即进行密码验证

时间:2011-08-11 10:44:09

标签: android passwords

我将此登录页面作为我的应用程序的第二页。 那里有4个编辑文本框。

我希望只要用户在第四个框中输入一个数字,然后不做任何操作,就会在活动中完成验证。

现在我已经设法放入onFocusChangeListener(),但它需要将焦点作为更改。

但我的要求是,一旦用户输入第四个框中的值而没有做任何事情,验证应该发生。 我的代码在这里。

        fourthBox.setOnFocusChangeListener(new OnFocusChangeListener() {

        public void onFocusChange(View v, boolean hasFocus) {
            // TODO Auto-generated method stub

            EditText firstBox=(EditText)findViewById(R.id.passCode1);
            EditText secondBox=(EditText)findViewById(R.id.passCode2);
            EditText thirdBox=(EditText)findViewById(R.id.passCode3);
            EditText fourthBox=(EditText)findViewById(R.id.passCode4);

            String firstBoxValue = firstBox.getText().toString();
             String secondBoxValue = secondBox.getText().toString();
             String thirdBoxValue = thirdBox.getText().toString();
             String fourthBoxValue = fourthBox.getText().toString();



            if((firstBoxValue.length()==0) || (secondBoxValue.length()==0) ||
            (thirdBoxValue.length()==0) || (fourthBoxValue.length()==0))

    {
        Toast.makeText(present.this,"Enter all four Passcodes",Toast.LENGTH_SHORT).show();

    }

2 个答案:

答案 0 :(得分:1)

您可以使用TextWatcher

为每次击键获得一个事件......

TextWatcher textWatcher = new TextWatcher() {
                                  public void beforeTextChanged(CharSequence s,
                                                                int start,
                                                                int count,
                                                                int after) {
                                  }

                                  public void onTextChanged(CharSequence s,
                                                            int start,
                                                            int before,
                                                            int count) {
                                  }

                                  public void afterTextChanged(Editable s) {
                                  }
                              }

et.addTextChangedListener(textWatcher);

答案 1 :(得分:0)

试试这个:

fourthBox.setOnClickListener(new EditText.OnClickListener(){
            public void onClick(View v) {
                // TODO Auto-generated method stub
            }
        });

上述想法不适合做这样的任务。你应该给用户按钮或其他东西开始验证..

相关问题