[英]Having issues with Handler in Android
I am creating a Handler
but for some reason the if statement
does not trigger
. 我正在创建一个
Handler
但由于某种原因if statement
不会trigger
。 The Log is printing out the correct value right before the if statement
. Log正在
if statement
之前打印出正确的值。
mHandler = new Handler() {
@Override public void handleMessage(Message msg) {
String s=(String)msg.obj;
s = s.trim();
Log.v("mHandler reply", s);
if(s == "OK"){
Dialog.dismiss();
}
}
}; };
Here is the log 这是日志
03-24 09:02:53.707: V/mHandler reply(7331): OK
Why is this not working? 为什么这不起作用?
Use equals()
method instead of ==
operator for String
comparison as follows... 使用
equals()
方法代替==
运算符进行String
比较,如下所示......
if(s.equals("OK")){
Dialog.dismiss();
}
To get more information check How do I compare strings in Java? 要获取更多信息,请查看如何比较Java中的字符串?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.