我正在尝试将整数数组与我独特制作的 ImageView 的标签进行比较。
使用这一行:
if(grid[i][j] == buttons[k].getTag()){
我知道我在正确的轨道上,但我不知道我是否需要施放它或使用某种方法。我知道这是一个简单的问题,但非常感谢任何帮助,谢谢。
最佳答案
标签是一个对象,所以放一个Integer
:
/*
* UseValueOf
* ----------
* Priority: 4 / 10
* Severity: Warning
* Category: Performance
*
* You should not call the constructor for wrapper classes directly, such as`new
* Integer(42)`. Instead, call the valueOf factory method, such as
* Integer.valueOf(42). This will typically use less memory because common
* integers such as 0 and 1 will share a single instance.
*/
//MyView.setTag(new Integer(42));
MyView.setTag(Integer.valueOf(42));
然后像这样检索值:
int tagValue = (Integer)MyView.getTag();
关于android - 将 View 的标签与整数进行比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10660438/