0

我有一個EditText與面具「## - ###。###」和結果是11-111.111,所以我決定使用TextWatch,所以我做了..EditText與驗證TextWatcher重複Android

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消息,執行兩次,我不」知道爲什麼...

+0

移動'Toast.makeText(DetalhesProdutos。這,「確定」,Toast.LENGTH_SHORT).show();'到'afterTextChanged' – rafsanahmad007

+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(); 
     } 
    } 
}); 
+0

它不工作,仍然重複兩次烤麪包! –

+0

我認爲你的代碼吐司一些錯誤檢查它,因爲它爲我工作 – sasikumar

+0

它的作品,但是當我刪除它的面具... –