Wednesday, 28 August 2013

split text with delimiters + int between 0-9

split text with delimiters + int between 0-9

I have to write a function that display string typed by the user , with
color in a textview.
Exemple : ^1Hi ^2 everyone:
"Hi" = red color because because there is "^1" before
"Everyone" = green color beacause there is "^2" before.
So I think I have to use split function like this :
String txt = myEditText.getText().toString();
String[] splits = txt.split("\\^(\\d+)");
But I don't know how to get number typed after "^".
And then I want tout assign a color with the number types.
And I think I can use :
MyTextView.setText(HTML.fromHtml(myTextModifiedWithColor);
So if you have any idea, it would be very appreciated.

No comments:

Post a Comment