-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