来自结果EditText的if语句

时间:2013-07-12 11:33:02

标签: android if-statement

我想使用if从结果类更改图像,但我不知道如何从result.getText显示图像。结果从1到100。

解决

CalculatorValue cv = new CalculatorValue ();
                    String calculationVal= cv.calculationVal(num1+ "compare" + num2);

                Result.setText(calculationVal+ " %");
if (result < 10){
        img.setBackgroundResource(R.drawable.ic_110);
    } 
在这种情况下,你能不能帮我举个例子

谢谢

代码无效

if (result < 10){
     // your code
} 
if (result >10 && result <15){
     // your code
}
else

我创建了Calculation.class,我将声明If放在MainActivity.class

此代码:

 CalculatorValue cv = new CalculatorValue ();
                    String calculationVal= cv.calculationVal(num1+ "compare" + num2);

                Result.setText(calculationVal+ " %");
if (result < 10){
        img.setBackgroundResource(R.drawable.ic_110);
    } 

运营商&lt;未定义参数类型String,int

1 个答案:

答案 0 :(得分:3)

您的案例中存在很大的语法错误。这是一个孤立的表达式,可以让编译器试图弄明白:

if (result >10 <15) // This is incomprehensible , doesn't work.

试试这个:

if (result < 10){
     // your code
} 
if (result >10 && result <15){
     // your code
}
else
  ....

问题编辑后:

  

运营商&lt;未定义参数类型String,int

清楚地表明resultString,因此无法使用<进行比较。一种方法是将result转换为intInteger.parseInt(result),请注意result是一个数字String,可以转换为有效int,例如121430。这不起作用12_3 ...

相关问题