验证Android后,使用TextWatcher重复EditText

时间:2017-03-27 06:37:20

标签: java android validation android-edittext android-textwatcher

我有EditText面具“## - ###。###”,结果是11-111.111,所以我决定使用TextWatch,所以我做了..

cepFrom.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if(s.length() == 10){
                //getCepFrom(s.toString());
                Toast.makeText(DetalhesProdutos.this, "OK", Toast.LENGTH_SHORT).show();
            }
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });

哪个会使用WebService,但仅用于测试,带有OK消息的Toast执行两次,我不知道为什么......

1 个答案:

答案 0 :(得分:0)

   cepFrom.addTextChangedListener(new TextWatcher() {
    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

    }

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

    }

    @Override
    public void afterTextChanged(Editable s) {
     if(cepFrom.getText().length() == 10){
            //getCepFrom(s.toString());
            Toast.makeText(DetalhesProdutos.this, "OK", Toast.LENGTH_SHORT).show();
        }
    }
});