Check in real time what you have typed in Edittext Android

2

I have an EditText that will receive the user data. It will click and enter a number between 1 and 10. I wanted to know if it has as I already checked so it jumps to another Edittext, if it actually put a number between 1 and 10. If it also posts, a message warning you of this .

The fact check I'm doing so it clicks the send data button. And only after this task do the verification. Can you do this verification before? As I mentioned above?

    
asked by anonymous 14.09.2017 / 20:02

1 answer

4

Give setOnFocusChangeListener on your EditText . Ex:

seuEditText.setOnFocusChangeListener(new OnFocusChangeListener() {          
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (!hasFocus) { //perdeu o foco
               Integer numero = Integer.parseInt(seuEditText.getText().toString()); //pega o número
               if (numero <=0 && numero >10) { //verifica se está entre 1 e 10
                   Toast.makeText(getApplicationContext(), 
                        "Número incorreto",
                         Toast.LENGTH_LONG).show(); //mostra a msg
                }
            }
        }
    });
    
14.09.2017 / 20:11