Stack Overflow archive
0 score

How can I optimize my syntax highlighting?

score
0
question views
152
license
CC BY-SA 3.0

Here are some suggestions:

Use a Handler and a Runnable instead of TimerTask. I'm assuming you want to wait n milliseconds before calling textHighLighter(Editable s) after afterTextChanged(final Editable s) is invoked. To do this, use handler.postDelayed(Runnable r, long delay) and handler.removeCallbacks(Runnable).

Remove Thread.sleep(2000).

An Editable extends CharSequence. Do no call toString() on your Editable, just pass it as an argument to Pattern#matcher(CharSequence).

Originally posted on Stack Overflow. Public user contributions are licensed under Creative Commons Attribution-ShareAlike.