Each EditText has its own Spannable. TextWatcher
's events has this Spannable as s
parameter.
I check their hashCode (unique Id of each object). myEditText1.getText() returns that Spannable.
So if the myEditText1.getText().hashCode()
equals with s.hashCode()
it means that s
belongs to myEditText1
So if you want to have one instance of TextWatcher for some EditTexts you should use this:
private TextWatcher generalTextWatcher = new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
if (myEditText1.getText().hashCode() == s.hashCode())
{
myEditText1_onTextChanged(s, start, before, count);
}
else if (myEditText2.getText().hashCode() == s.hashCode())
{
myEditText2_onTextChanged(s, start, before, count);
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
if (myEditText1.getText().hashCode() == s.hashCode())
{
myEditText1_beforeTextChanged(s, start, count, after);
}
else if (myEditText2.getText().hashCode() == s.hashCode())
{
myEditText2_beforeTextChanged(s, start, count, after);
}
}
@Override
public void afterTextChanged(Editable s) {
if (myEditText1.getText().hashCode() == s.hashCode())
{
myEditText1_afterTextChanged(s);
}
else if (myEditText2.getText().hashCode() == s.hashCode())
{
myEditText2_afterTextChanged(s);
}
}
};
Each EditText has its own Spannable.
TextWatcher
events has this Spannable asCharSequence
orEditable
parameters. I do not check the Text value of EditTexts. I check their hashCode (unique Id of each object).myEditText1.getText()
returns thatSpannable
not the Text value. So if themyEditText1.getText().hashCode()
equals withs.hashCode()
means that s belongs tomyEditText1