无法将字符串转换为整数java

时间:2016-04-24 19:31:07

标签: java android string if-statement int

所以,如果它的值大于0,我需要将textView颜色更改为红色,如果它小于0,我需要将其更改为绿色,但是如果语句正确则我无法写入,因为textView是一个字符串,但我已将其更改为int。

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

    }

1 个答案:

答案 0 :(得分:0)

要使用String内的TextView(不是String,而是View),您首先需要.getText().toString()访问String stringValue = textView.getText().toString(); int intValue = Integer.parseInt(stringValue); //Now do your logic. 1}}。因此,如果您希望像整数一样使用textView的值,请执行以下操作:

String

如果您想再次将值设置为视图,请确保您传递的是[SCNTransaction begin]; [SCNTransaction setAnimationDuration:0]; ... [SCNTransaction commit]; 而不是整数。