I'm working on a kind of typing game on Android. It has a Text View with the sentence the user has to type in. Each time the current word the user has to type in will be underlined, once user finished a word, that word will change color based on the time it took to type (e.g. >5 seconds = red, <5 seconds is green).
My question is how can I underline and change the color of the words in the Text View so that when I underline a new word, it will also keep the color of the previous ones?
Currently I'm doing some thing like this every time I move to the next word
String texts = myTextView.getText().toString();
// put the next word to be underlined between <u> </u> tags
myTextView.setText(Html.fromHtml(texts));
As you can see, it will underline the next word but all of the colors of the previous words will be lost but I want to keep those.
Thanks for your help!
Edit: My text is already fixed and the user has to type in the words they see. For example, I have a sentence "Sample Sentence Hello". I want "Sample" to be underlined at first, then "Sentence" underlined, "Sample" changed red or green, then "Hello" underlined and "Sample" and "Sentence" each changed to red or green depending on the time it took the user to type each word.