2 baby bonnie Baby_Bonnie 于 2012.11.30 15:02 提问

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);

请求大家的帮忙,谢谢!

1个回答

cytown
cytown   2012.11.30 15:06
已采纳
 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);
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!