[英]getTag() returning a false string
I've set a tag on an imageview to be "blank", so it looks like this in the xml file 我在imageview上设置了一个标签为“空白”,因此在xml文件中看起来像这样
android:tag="blank"
Now when I run this 现在当我运行这个
((String) buttons[button-2].getTag() == "blank"
It returns false. 它返回false。 I can't find why, any ideas?
我找不到原因,有什么想法吗? Any help greatly appreciated.
任何帮助非常感谢。
Use: 采用:
((String) buttons[button-2].getTag().equals("blank")
For String
comparison you must use equals
, ==
tests references. 对于
String
比较,必须使用equals
, ==
测试引用。
You can also intern
the String. 您也可以
intern
字符串。 This always produces the same object for the same string contents, so you can do comparisons with ==
. 对于相同的字符串内容,这总是产生相同的对象,因此可以使用
==
进行比较。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.