Baby_Bonnie 2012-11-30 07:02 采纳率: 96.4%
浏览 2565
已采纳

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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突