Reusing images in same layout

Go To StackoverFlow.com

0

I was wondering if it was possible to reuse the same imageview more then once on the same layout.

Example: I'm working on a tic tac toe game for android in eclipse. I have drawn the table, x's, o's to give more of a visual appeal. I want to reuse the x's o's instead of creating x1..x9 and o1..o9 can I reuse a imageview and specify where I want it to be positioned?

Thanks

2012-04-03 23:05
by s.nguyen


0

No, I'm afraid you can't.. but more realistically, wouldn't you just want square1...square9 and set that square's source? for example, something like:

public void onClick(View v) {
  ImageView square = (ImageView) v;
  if(lastClickWasO) {
    square.setImageResource(R.drawable.x);
    lastClickWasO = false;
  }
  else {
    square.setImageResource(R.drawable.o);
    lastClickWasO = true;
  }
}
2012-04-03 23:21
by JRaymond