How to use textwatcher to count how many characters it has in a textview, and show countdown, the same is done on facebook by limiting a post. Thank you in advance!
How to use textwatcher to count how many characters it has in a textview, and show countdown, the same is done on facebook by limiting a post. Thank you in advance!
See an example of a limitation of 150 characters (visually only):
editText.addTextChangedListener(new TextWatcher()
{
@Override
public void onTextChanged(CharSequence s, int start, int before, int count)
{
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int aft)
{
}
@Override
public void afterTextChanged(Editable s)
{
textView.setText(150 - s.toString().length() + "/150");
}
});
So, soon afterwards you just have to make a condition so that you do not have to send the data if the EditText
has more than the amount of characters previously defined.
See below how it would look: