Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comparing a view's tag to an integer

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.

like image 707
Benny292 Avatar asked May 18 '12 22:05

Benny292


2 Answers

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();
like image 87
tdevaux Avatar answered Oct 14 '22 04:10

tdevaux


You have to convert buttons[k].getTag() in integer.

Do this:

if(grid[i][j] == Integer.parseInt(buttons[k].getTag().toString())){
like image 26
Karn Shah Avatar answered Oct 14 '22 05:10

Karn Shah