How to use the textwatcher?

Asked

Viewed 1,088 times

1

How to use the textwatcher to count how many characters you have in a textview ,and show in countdown , the same is done on facebook by limiting a post. Thank you in advance!

1 answer

2


See an example of a 150-character limitation (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 after, just make a condition so that do not let send the data if the EditText has more than the number of characters previously defined.

See below how it would look:

inserir a descrição da imagem aqui

  • Ack, here comes that textview counting how much you type?

  • You can create an independent Textview to show the count.

  • Or you wanted to show otherwise?

  • an editText and a textView

  • the textView takes the count...

  • so I understand, Thank you

  • @Wallaceroberto saw the image I placed. Edittext on top with a Textview on the bottom counting. = D

  • 1

    Show, very good, exactly what I want!

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.