If my row is colored red the text won’t set to green and bold italic. When debugging I can see it telling the TextView to set each textViews setting.
TableRow row = new TableRow(getContext());
row.setLayoutParams(new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
String[] items = list.get(l).split(":");
for(int i=0; i < items.length; i++){
//see if i need to colour row
if(items[i].startsWith("colorme_") == true) {
if (items[i].substring(8).equals("red") == true) {
row.setBackgroundColor(Color.RED);
}
} else {
//create a temp textview then add to row
TextView tempTV = new TextView(getContext());
tempTV.setText(items[i].toString());
//test against correct answers and colour text view green if correct
if (correctAnswers != null && correctAnswers.size() > i) {
if (correctAnswers.get(i).equals(items[i].toString()) == true) {
tempTV.setTextColor(Color.GREEN);
tempTV.setTypeface(null, Typeface.BOLD_ITALIC);
}
}
row.addView(tempTV,lpTextView);
}
}
//add the row
tempTable.addView(row);
To me it looks like you have separated the two different color setting codes on different sides on an
if elseso they won’t both get called at the same time, because if theifstatement returns true, then the else statement will not be triggered and you will pass thesetTextColorcode without running it and vice versa, if the if statement returns false, then you will skip changing the background color and only change the text color.Hope that makes sense
Edit here is an example