我想检查strCurrentSpeed
是否大于或等于" 10"。
我怎么做?我收到错误 - "运算符> =未定义参数类型String,int"我知道这是非常基本但我无法找到解决方法
public void updateSpeed(CLocation location)
{
float nCurrentSpeed = 0;
if( location!=null )
{
location.setUseMetricUnits(this.useMetricUnits());
nCurrentSpeed = location.getSpeed();
}
Formatter fmt = new Formatter(new StringBuilder());
fmt.format(Locale.US, "%5.1f", nCurrentSpeed);
String strCurrentSpeed = fmt.toString();
strCurrentSpeed = strCurrentSpeed.replace(' ', '0');
String strUnits = "miles/hour";
if (this.useMetricUnits())
{
strUnits = "meters/second";
}
TextView txtCurrentSpeed = (TextView) this.findViewById(R.id.txtCurrentSpeed);
txtCurrentSpeed.setText(strCurrentSpeed + " " + strUnits);
if (strCurrentSpeed >= 10){
//do action
}}
答案 0 :(得分:-1)
您可以执行以下操作:
if (Integer.valueOf(strCurrentSpeed) >= 10) {
//Whatever
}
答案 1 :(得分:-2)
使用显式转换:
if(Integer.parseInt(strCurrentSpeed) >=10)
{
// Do you stuff
}