2012-03-23 68 views
2

如何在打字過程中讓textwatcher從250減少到0? android:maxLength="250"設置,這樣就不會低於0.1Android textwatcher倒數

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

回答

0

適用於它InputFilter.LengthFilter並設置上限爲250個字符,並在方法afterTextChanged您的計數器設置爲250 - 文本

+0

TVC的長度.setText(String.valueOf(250 - s.length()));在ontTextChanged就足夠了。感謝您的想法! – erdomester 2012-03-23 16:18:23