forum

Home / DeveloperSection / Forums / TextWatchers, OnClickListeners in android

TextWatchers, OnClickListeners in android

Anonymous User176906-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()
{
    publicvoid afterTextChanged(Editable s)
    {              
         // some code here
    }
 
    publicvoid beforeTextChanged(CharSequence s, int start, int count, int after)
    {
         //and/or here
    }
 
    publicvoid 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