2
我有一個EditText
並有一個TextWatcher
它。使用TextWatcher檢測刪除的最後文本
我在其中輸入數字,如果最後一個文本被刪除,我想用0填充該字段。
我該如何使用TextWatcher
這三種方法?
input.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void afterTextChanged(Editable s) {
double value=Double.parseDouble(input.getText().toString());//here it will throw error if no text there.
//I do not only want to catch this exception and do something with it, but I want to detect this event and if it happens I want to try some solution to stop it.
}
});
檢查,如果S的長度等於0,或者如果s爲null – 2014-10-02 05:10:06