getTag() returning a false string
-
09-06-2021 - |
Question
I've set a tag on an imageview to be "blank", so it looks like this in the xml file
android:tag="blank"
Now when I run this
((String) buttons[button-2].getTag() == "blank"
It returns false. I can't find why, any ideas? Any help greatly appreciated.
Solution
Use:
((String) buttons[button-2].getTag().equals("blank")
For String
comparison you must use equals
, ==
tests references.
OTHER TIPS
You can also intern
the String. This always produces the same object for the same string contents, so you can do comparisons with ==
.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow