Often times there is a necessity for an app to display multiple EditText inputs. For example, lets take a look at this screen in my application Orderise.

There are two EditText input boxes namely, a special_orders and a name box.

It is possible to have a single TextWatcher for multiple EditTexts, like so:

//first define each EditText
EditText nameText = (EditText) findViewById(R.id.name);
EditText specialOrders = (EditText) findViewById(R.id.special_instructions);

//Next add textwatchers for each editText. You will need to get the activity or fragment that contains them to implement TextWatcher
nameText.addTextChangedListener(this);
special_orders.addTextChangedListener(this);

Now, this is where it gets interesting. You see, if this were multiple Buttons for a single OnClickListener, it would be easy as pie - just get the activity to implement the OnClickListener and then look for each Button’s Id to be able to detect which button was clicked. Something like:

Button button1 = (Button) findViewById(R.id.button1);
Button button2 = (Button) findViewById(R.id.button2);
button1.setOnClickListener(this);
button2.setOnClickListener(this);

@Override
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.button1: {
            //do something useful here.
            }
        case R.id.button2: {
            //do something else useful here.
            break;
        }
      }

But unfortunately, with TextWatcher we do not have the luxury of the the View object being passed into the Overridden methods of beforeTextChanged, onTextChanged and afterTextChanged. But there is still a way. For example, in the afterTextChanged method, we can compare the hashCode for the Editable Object with the Text in the EditText object, like so:

@Override
public void afterTextChanged(Editable s) {
  if (s.hashCode() == nameText.getText().hashCode()) {
      //Do else something with input.
  } else if (s.hashCode() == specialOrders.getText().hashCode()) {
      //Do something else useful with input.
  }
}

There are of course a few other ways - one is to subclass the EditText Class and then pass the EditText View object into the three methods. But I believe the solution above is a bit more elegant.