Setting color of specific keywords in a textview
First of all, some side notes:


In your keywordsgreen array, you're checking for very specific library names. But you also check for #include and #define. So what if I include &lt;stdlib.h&gt;? Your current code would search the text, find #include, turn it green, then search again, find &lt;stdlib&gt; and turn that green. But the whole line might as well be green. Instead, just look for the # symbol at the absolute start of the line (it would take a little more logic, of course). That way, you eliminate most of the keywordsgreen array.
Also, you're setting the text every single time you edit a single word. You don't need to do that. Just keep one SpannableString and pass that around, setting the textView to that all the way at the end of the function.
I don't think this should be that slow. It's not a very good solution, but even for a 300-line source file, I can't imagine it would take 5 seconds. Put all that in a new thread and see what happens.

Example:

Thread colorTextThread = new Thread(new Runnable(){
public void run(){ 
  //Put all that searching code in here
}//end of run
});
colorTextThread.start();



You put it on a new thread because the UI thread is super slow. Remember, though, if you want to change the textView on a separate thread, you have to use the runOnUiThread() function.

I'll add more later if no one tells you how to make the code faster. I've got to go at the moment, sorry.

EDIT:

After looking at your code again, I can't see a way to make it faster. The most important things you can do is to do the search on the "programText" variable you're passing to textView. That variable holds all the information you need, so you should manipulate that, and then pass it to textView.setText(). That way, you never have to call getText(), which means you can do all of your text processing on a separate thread. If it runs slow even on a separate thread, then yes, your code is very slow. Otherwise, problem solved for now.