0

如果我的行是红色的,则文本不会设置为绿色和粗斜体。调试时,我可以看到它告诉 TextView 设置每个 textViews 设置。

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

1 回答 1

1

对我来说,您似乎已将不同侧面的两个不同颜色设置代码分开,if else因此它们不会同时被调用,因为如果if语句返回 true,则不会触发 else 语句,您将通过setTextColor代码而不运行它,反之亦然,如果 if 语句返回 false,那么您将跳过更改背景颜色而仅更改文本颜色。

希望这是有道理的

编辑这里是一个例子

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
}
于 2012-11-11T22:36:54.760 回答