Baby_Bonnie
2012-11-30 07:02
采纳率: 96.4%
浏览 2.6k

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条回答 默认 最新

  • Billy_崔海斌 2012-11-30 07: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);
    
    已采纳该答案
    打赏 评论

相关推荐 更多相似问题