android - Switch Statement using a loop in Java -
i have switch statement alter image resourceid:
int imageid = 0; switch (i) { case 0: imageid = r.drawable.image0; break; case 1: imageid = r.drawable.image1; break; case 2: imageid = r.drawable.image2; break; case 3: imageid = r.drawable.image3; break; case 4: imageid = r.drawable.image4; break; case 5: imageid = r.drawable.image5; break; case 6: imageid = r.drawable.image6; break; case 7: imageid = r.drawable.image7; break; }
but have been trying find out how using loop, since case number , number @ end of each image matches. tried loop without success.
can help?
thx!!
why not give r.drawable array of images , can below ?
imageid = r.drawable.images[i];
here's the oracle tutorial. alternatives include java.util.list
of particular implementation e.g. arraylist
java android loops for-loop switch-statement
No comments:
Post a Comment