locoboy
locoboy

Reputation: 38960

Swapping images in a table layout

I have a 2D array of ImageViews and am currently displaying each of them in a tableLayout. If I wanted to switch the ImageViews, I think that I need to swap the bitmaps that each [i][j] imageViews are assigned to. For example, if I wanted to swap positions of the images at [0][0] and [0][1], how would I do this?

I have a feeling that I would need to reassign each underlying bitmap to the appropriate imageview.

Upvotes: 0

Views: 811

Answers (1)

Chris
Chris

Reputation: 7853

You could try getting the Drawable, on the imageviews and save it to variables:

Drawable d1 = imageViews[0][0].getDrawable();
Drawable d2 = imageViews[0][1].getDrawable();

Then you swap the drawables by:

imageViews[0][0].setImageDrawable(d2);
imageViews[0][1].setImageDrawable(d1);

I think that will switch the images of the views, or do you actually need to move the positions of the imageviews?

Upvotes: 1

Related Questions