android - 将 View 的标签与整数进行比较

标签 android tags integer compare

我正在尝试将整数数组与我独特制作的 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/

相关文章:

android - Espresso 如何等待一段时间(1 小时)?

android - child Android 的 ExpandableListView 动画

java - Android 内存泄漏新线程()

android - 如何设置高程颜色?

MySQL加入其中一个字段周围的标签被剥离

c++ - 如何在 C++ 中将纬度的小数部分存储到 4 个无符号字符中

html - 从 CSS 内置的标签形状中删除白色背景

php - 将 img src 替换为 php

python - 在 Python 中计算最多两位小数

C:如何迭代 `signed int` 的所有可能值,从 `INT_MIN` 到 `INT_MAX` ?