如何让 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);
最佳答案
对其应用 InputFilter.LengthFilter 并将限制设置为 250 个字符,并在方法 afterTextChanged
中将计数器设置为 250 - 文本长度
关于Android textwatcher倒计时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9841993/