Your TextWathcer
changes the text that it is watching, causing another call to the watcher, causing another change to the text, ... and so on until you run out of stack space invoking methods.
One way to fix it is to set up a boolean
flag to true
when you're running inside the watcher and return immediately if the flag is set to kill the recursion. In pseudocode:
boolean mIsInWatcher = false;
void onTextChanged(...) {
if (mIsInWatcher) return;
mIsInWatcher = true;
// text modifications here
mIsInWatcher = false;
}