how to setTag for int Array in Android -
i'm learning android , can appropriate not question , 'd appreciate help
i'm trying make memory game , have 2 arrays named imgback imageview array of buttons , int array of images called imgface
i need settag() int array called imgface
when try settag() int array (imagesface) not possible because belongs view , if make array of imgface imageview array can not setimageresource() cardimg (becouse required int)
i add section of code
thank again answer
for (int = 0; < 12; i++) { imgback[i].setimageresource(r.drawable.icon); final int imagesface = imgface[position[i] - 1]; final imageview cardimg = imgback[i]; //cardimg.settag(i); cardimg.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { cardimg.setimageresource(imagesface); imageview cardthatwasclicked = (imageview) v; int cardid = (int) cardthatwasclicked.gettag(); counter++; if (counter % 2 == 0) {//b cardb = cardid; if (cardb == carda) { toast.maketext(getbasecontext(), "match!", toast.length_long).show(); } else { toast.maketext(getbasecontext(), "not match!", toast.length_long).show(); } } else {//a if (carda != -1) { imgback[carda].setimageresource(r.drawable.icon); imgback[cardb].setimageresource(r.drawable.icon); } carda = cardid; } } }); }
you can write:
cardimg.settag(new integer(i));
and like:
int = (int) cardimg.gettag();
note: settag
method takes input argument of type object
. in java int
, float
, ... primitive types , not extend java object
base class. integer
, float
, ... equivalent classes extend base object
class.
Comments
Post a Comment