Domanda

How can I make a textwatcher count down from 250 to 0 during typing? android:maxLength="250" is set, so it won't go below 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);
È stato utile?

Soluzione

apply to it InputFilter.LengthFilter and set limit to 250 characters and in method afterTextChanged set your counter to 250 - length of the text

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top