我想在程序中设置一个textwatcher,在打字时能倒数计时,从250倒数到0。我设置android:maxLength="250"。但是这个方法不能倒数到0.
这是我用的代码:
et_Notes = (EditText) dialog_list.findViewById(R.id.EditText_Notes);
tvC = (TextView)dialog_list.findViewById(R.id.TextViewCounter);
final TextWatcher mTextEditorWatcher = new TextWatcher() {
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
tvC.setText(String.valueOf(s.length()));
}
public void afterTextChanged(Editable s) {
}
};
et_Notes.addTextChangedListener(mTextEditorWatcher);
请求大家的帮忙,谢谢!
et_Notes = (EditText) dialog_list.findViewById(R.id.EditText_Notes);
tvC = (TextView)dialog_list.findViewById(R.id.TextViewCounter);
final TextWatcher mTextEditorWatcher = new TextWatcher() {
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
public void afterTextChanged(Editable s) {
tvC.setText(String.valueOf(250 - s.getText().length()));
}
};
et_Notes.addTextChangedListener(mTextEditorWatcher);