- Code: Select all
if (pic1 == 1) {
pic1.setImageResource(R.drawable.blue);
}
if (pic1 == 2) {
pic1.setImageResource(R.drawable.red);
}
if (pic1 == 3) {
pic1.setImageResource(R.drawable.green);
}
if (pic2 == 1) {
pic2.setImageResource(R.drawable.blue);
}
etc.
Because I have lots of pictures, the code is really long and wastes time whenever I need to change it. The pictures all need unique names but they all change to the same drawables for each state (any that are state 1 are "blue", etc.).
Is there a way to simplify this code and just say, "For all you pictures, if your state is 1 then setImageResource(R.drawable.blue)"?
Thanks for any help you can give!

. You should store your pictures, and their states in an array (or if you delete/remove them often, a suitable List). With an array you can easily do this:
I'll just warn you, itll be a bumpy ride 