getTag() returning a false string

2.7k Views Asked by At

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.

2

There are 2 best solutions below

3
On BEST ANSWER

Use:

((String) buttons[button-2].getTag().equals("blank")

For String comparison you must use equals, == tests references.

0
On

You can also intern the String. This always produces the same object for the same string contents, so you can do comparisons with ==.