我有一个带有掩码"##-###.###"的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) {
}
});
这将消耗 Web 服务,但仅用于测试,带有 OK 消息的 Toast 执行两次,我不知道为什么......
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();
}
}
});