The following code snippet is used for a text Watcher…it doesnt work…everything works fine,untill the last line of code…
private TextWatcher mobileTextWatcher = 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 after) {
}
@Override
public void afterTextChanged(Editable s) {
String number = s.toString();
number = AppConstants.convertToOnlyDigits(number);
Editable temp = new SpannableStringBuilder(
AppConstants.formatPhoneNumber(number));
s = temp;
}
};
After that the new doesn’t get assigned to s.. Or in otherwords,I cannot see a change in the text in the Edit Text.
You are not changing the object in
s, you are instead replacing the variableswith another object.Try something like this:
Note I’ve added some protection to stop
afterTextChangedbeing called when you changesobject (which I assume has a DataObserver placed on it). Recursion protection is off the top of my head so might need tweaking.Hope this helps.