-2
所以,我需要将我的textView颜色更改为红色,如果它大于0,并且如果它小于0则为绿色,但我无法正确写入if语句,因为textView是一个字符串,但我已经把它改为int。无法比较字符串转换为整数java
textView.setText(textView + "");
if(textView > 0) {
textView.setTextColor(this.getResources().getColor(R.color.colorAccent));
}
else if (textView < 0){
textView.setTextColor(this.getResources().getColor(R.color.colorPrimary));
}
else {
textView.setTextColor(this.getResources().getColor(R.color.colorPrimaryDark));
}
'textView'似乎是一个GUI组件。你正在对'setText'调用你不能用'int'值做的事情。 –
按如下方式重新排序:'textView.setText(“”+ textView);' – Vucko
这种隐式转换方式将为您处理。 :d – Vucko