我目前正在尝试处理结果,如果收到输入并遇到一些麻烦,我希望能够将文本设置为特定短语,如果没有结果,并希望能够拥有如果有,输入显示正确。我目前正在尝试这个:
String s = scanningResult.getContents();
if (s == null){
s="Location Is here,Time is here,Cost is here";
}
else {
s=s;
}
String [] s2 = s.split(",");
TextView location = (TextView)findViewById(R.id.LocationResult);
location.setText(s2[0]);
TextView time = (TextView)findViewById(R.id.TimeResult);
if (s2[1] == "Time is here"){
time.setText("Time is here");
}
else {
time.setText(s2[1]+" Seconds");
}
TextView cost = (TextView)findViewById(R.id.CostResult);
if (s2[2] == "Cost is here"){
cost.setText("Cost is here");
}
else {
cost.setText("$"+s2[2]);
}
}
我遇到的问题是,在null scanningResult
上,time
和cost
两个值将显示为Time is here Seconds
和$Cost is here
。我不明白为什么。
答案 0 :(得分:4)
使用equals
方法来比较String
if (s2[1].equals("Time is here")){ }