I need to know which image is in which cell, so I have only tried using .setId() and .getId(). But if there’s any other way to do this, just let me know.
Images are added when I click a button. I have nothing showing where they appear, but here’s my problem, I’m trying to add a Id to each image that I’m able to add. So when I drop them in the GridView and click one of them I can do something else if the Id is the correct one, like, if (Id == 1) open... else if (id == 2) open other thing. But I can’t get the Id to be saved to the image (or saved to that ImageCell).
Example of the problem I’m getting: If I added image1 which have Id1 and then add image2 which have Id2 the image1 Id will change to the last image added (in this case image2 Id). I have tried a lot of different ways of setting the Id, but I’m still getting the last image id in the first one dropped.
I’m using a Toast to show the image dropped Id. This is the ImageCell code.
public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset,
DragView dragView, Object dragInfo)
{
mEmpty = false;
ImageView sourceView = (ImageView) source;
sourceView.setId(DragActivity.m);
Drawable d = sourceView.getDrawable ();
this.setId(sourceView.getId());
if (d != null) {
this.setImageDrawable (d);
this.setId(sourceView.getId());
prueba = this.getId();
}
toast ("" + prueba);
}
DragActivity.m is just a variable that’s used to change the picture.
public void addNewImageToScreen() {
int resourceId = R.drawable.hello;
m = mImageCount % 3;
if (m == 1) {
resourceId = R.drawable.photo1;
} else if (m == 2) {
resourceId = R.drawable.photo2;
}
addNewImageToScreen(resourceId);
}
Anyone know what I’m doing wrong? Thanks
I think you are trying to swap images in that case you can identify
ImageViewuniquely by tag like this:And then on
GridView‘s /ImageView‘s click check its tag like this: