Remove setError after field is filled

1

I put a setError, telling the user to fill in the form if it did not, but after filling it it was to clear the error, however, I did it using setErrorEnable (False) but it did not work.

    public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    showKeyboard(getContext());
    //inicio calcular rpm
    inputLayoutcormecial = (TextInputLayout) getView().findViewById(R.id.textinputcorm);
    inputLayoutvcorte = (TextInputLayout) getView().findViewById(R.id.textinputVC);
    veditTextCormecial = (EditText) getView().findViewById(R.id.editTextComercial);
    veditTextVC = (EditText) getView().findViewById(R.id.editTextVC);
    txtresultado = (TextView) getView().findViewById(R.id.textViewResultRPM);
    Button botaocal = (Button) getView().findViewById(R.id.buttonCalc);
    veditTextCormecial.requestFocus();

    //clique do botao calc
    botaocal.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if (veditTextCormecial.getText().toString().matches("")) {
                inputLayoutcormecial.setError(getString(R.string.campo_vazio));
                veditTextCormecial.requestFocus();
                return;

            }
            else if (veditTextVC.getText().toString().matches("")) {
                inputLayoutvcorte.setError(getString(R.string.campo_vazio));
                veditTextVC.requestFocus();
                return;
            }
            else if (veditTextCormecial.getText().toString() != ""){
                inputLayoutcormecial.setErrorEnabled(false);
            }
            else if (veditTextVC.getText().toString() != ""){
                inputLayoutvcorte.setErrorEnabled(false);
            }
            else {
                valorComer = Double.parseDouble(veditTextCormecial.getText().toString().replace(",","."));
                valorVC = Double.parseDouble((veditTextVC.getText().toString()).replace(",","."));
                vresultado = valorVC * 1000 / (3.14 * valorComer);
                DecimalFormat formato = new DecimalFormat("#.##");
                vresultado = Double.valueOf(formato.format(vresultado));
                //exibir resultado
                txtresultado.setText(vresultado.toString() + " RPM");
                txtresultado.setVisibility(View.VISIBLE);
            }

        }
    });
    //fim calcular rpm

    
asked by anonymous 31.12.2016 / 02:24

1 answer

2

You need to use the TextWatcher class in your EditText .

EditText userName = (EditText) findViewById(R.id.username);
userName.addTextChangedListener(new TextWatcher() {
    @Override
    public void afterTextChanged(Editable s) {
        // TODO Auto-generated method stub
    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after){
        // TODO Auto-generated method stub
    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count){
        // Quando o texto for alterado, verifique de novo se contém o erro
        // se o erro for corrigido, basta colocar setError como false
    } 
});

The last method is the most important because it is where you can manipulate what you want to do after the text changes .

    
31.12.2016 / 03:30