Android textwatcher倒计时

标签 android textwatcher

如何让 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/

相关文章:

java - 找不到 gradle 包装器

android - 收到错误 : 'shared_ptr' in namespace 'std' does not name a type

android - onConfigurationChanged 重新排列方向布局

android - TextEdit值改变时如何触发?

android - 如何在用户键入时用不同的注释替换一个注释(将 “space” 替换为 “-”

android - backgroundTint 对 Lollipop 版本没有影响

android - 如何在 Android 上使用 TextWatcher 处理回车键

android - 用于多个 EditText 字段的 TextWatcher

android - 通过edittext设置文本到textview

Android:ListView 在出现软键盘时反转项目