RuAware RuAware - 17 days ago 7
Android Question

TextColor not showing when row backgroundcolor set

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);

jcw jcw
Answer

To me it looks like you have separated the two different color setting codes on different sides on an if else so they won't both get called at the same time, because if the if statement returns true, then the else statement will not be triggered and you will pass the setTextColor code 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

if(items[i].startsWith("colorme_") == true) {
    //this is where your are preforming your change row color to red
} else{
    //this is where you are setting your text color to green
}
Comments