Remove setError after field is completed

Asked

Viewed 126 times

1

I put a setError , warning the user to fill in the form if they had not, however after it filled out was to disappear the error, but continues, I did 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

inserir a descrição da imagem aqui

1 answer

2


You need to use the class Textwatcher in your(s) 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 will be able to manipulate what you want to do after the text is amended.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.