RuAware RuAware - 10 months ago 47
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) {
} else {
//create a temp textview then add to row
TextView tempTV = new TextView(getContext());
//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.setTypeface(null, Typeface.BOLD_ITALIC);
//add the row

jcw jcw
Answer Source

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