forum

home / developersection / forums / textwatchers, onclicklisteners in android

TextWatchers, OnClickListeners in android

Anonymous User 2054 06-Nov-2014

Just wondering if there is any best practice on the use of TextWatchers, OnClickListeners and such like with regards to how you put them in code.

Would you do the following:

textBox.addTextChangedListener(new TextWatcher()
{
    public void afterTextChanged(Editable s)
    {              
         // some code here
    }
 
    public void beforeTextChanged(CharSequence s, int start, int count, int after)
    {
         //and/or here
    }
 
    public void onTextChanged(CharSequence s, int start, int before, int count)
    {
         //and/or even here
    }
 });

Or would it be best to have the TextWatcher etc as a variable and call it like:

textBox.addTextChangedListener(myTextWatcher);

I understand the second would be far better for reusability but  was curious about if there is only one instance of the, in this example, TextWatcher.


Updated on 07-Nov-2014

I am a content writter !

Can you answer this question?

Answer

1 Answers

Liked By