Comparing a View Tag with an Integer

I am trying to compare an array of integers with image tags, which I made uniquely.

using this line:

if(grid[i][j] == buttons[k].getTag()){

I know im on the correct tracks, but I cannot figure out if I need to use it or use the method. I know this is a simple question, but any help would be greatly appreciated, thanks.

+5
source share
4 answers

I think your tag is more a string than an integer.

If this event converts your Integer toString () and check if it is equal ().

+3
source

A tag is an object, so put 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 extract a value like this:

int tagValue = (Integer)MyView.getTag();
+18
source

[k].getTag() .

:

if(grid[i][j] == Integer.parseInt(buttons[k].getTag().toString())){
+10

.

int Index = Integer.parseInt(v.getTag().toString());
System.out.println(Index);
0

All Articles