字符串颜色不会显示在循环中? Android的

时间:2016-12-06 09:47:06

标签: android

正如您所看到的,我将字符串设置为2种不同的颜色并在"完成"上进行测试。 TextView,它确实改变了字符串颜色。但是一旦我将它放在循环内的TextView上,它只显示String而不显示颜色。我该如何解决这个问题?谢谢!

String red = " Missing";
SpannableString redSpannable= new SpannableString(red);
redSpannable.setSpan(new ForegroundColorSpan(Color.RED), 0, red.length(), 0);
// **complete.setText(redSpannable);**

String green = " Complete";
SpannableString greenspan= new SpannableString(green);
greenspan.setSpan(new ForegroundColorSpan(Color.GREEN), 0, green.length(), 0);

for (int i = 0; i < lengthJsonArr; i++) {

    int rem = ingnum.get(i) - (added[i] - 1);
    Log.v("Final", ingnum.get(i).toString());

    if (rem == 0) {
        jsonParsedfinal.setText(jsonParsedname.getText() + title.get(i) + greenspan + "\n"
                + "\n"
                + "Ingredients: " + jsonParseding.getText() + ingre.get(i) + "\n"
                + "\n"
                + "Link: " + jsonParsedlink.getText() + link.get(i) + "\n"

                + "------------------------------------------------------------------------------------------");

    } else {
        jsonParsedfinal.setText(jsonParsedname.getText() + title.get(i) + " " + rem + redSpannable + "\n"
                + "\n"
                + "Ingredients: " + jsonParseding.getText() + ingre.get(i) + "\n"
                + "\n"
                + "Link: " + jsonParsedlink.getText() + link.get(i) + "\n"

                + "------------------------------------------------------------------------------------------");
    }
}

1 个答案:

答案 0 :(得分:0)

使用spannable缓冲区合并字符串

76*(10**-8)