I'm working on a small project and I can not get the expected result. I would like change color odd words of a string and the other another color. Can anyone help? I leave here my current code:
public void updateMessages() {
String groupMessage = "Admin says: Hi people\n Admin says: What's up?";
TextView groupMessageBox = (TextView) this
.findViewById(R.id.groupMessageBox);
String[] str_array = groupMessage.split("\n|\\:");
//Result str_array == Admin says, Admin says
for (int i = 0; i < str_array.length; i++) {
//Get values of array
String val1 = str_array[i];
//Only numbers pairs
if ( i % 2 == 0 ) {
//How to change the result to blue, for example?
Log.e("",val1);
}else{
Log.e("",val1);
//How to change the result to red, for example?
}
}
groupMessageBox.setText(groupMessage);
}
Greetings!