2

如何在打字过程中让 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);
4

1 回答 1

0

应用到它 InputFilter.LengthFilter 并将限制设置为 250 个字符,并在方法afterTextChanged中将您的计数器设置为 250 - 文本的长度

于 2012-03-23T15:35:40.893 回答