If user types a String and it contains @ i want to change the color of the text to red.i have tried with textwatcher but got stack overflow error.I want to change the color only if the @ is at the beginning.The code is given below
topic.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence s, int start, int before,
int count) {
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
public void afterTextChanged(Editable s) {
if (s.toString().matches("(@\\w+)")) {
topic.setText(Html.fromHtml(s.toString().replaceAll(
"(@\\w+)", "<font color='#ffff0000'>$1</font>")));
}
}
});
append to bring curser at end of line and set text null before appending
You have to remove the textwatcher before you set the new text to edit text. Try this code
Try this:
This is a textWatcher Metod