I'm trying to compare an array of integers to the tags of imageviews I have uniquely made.
using this line:
if(grid[i][j] == buttons[k].getTag()){
I know im on the right tracks, but I can't figure out if i need to cast it or use a method. I know its a simple question, but any help would be greatly appreciated, thanks.
Tag is an Object, so put an 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));
Then retrieve the value like this:
int tagValue = (Integer)MyView.getTag();
You have to convert buttons[k].getTag() in integer.
Do this:
if(grid[i][j] == Integer.parseInt(buttons[k].getTag().toString())){
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With