Android ImageView Loop
I have a set of 4 image views I created in XML, and I am able to do OnTouch on them and they do a visi开发者_运维问答ble and invisible. But now I want to do a Invisible and Visible in a sequence,,,, so basically image1 shows, image1 does not show, image 2 shows, image 2 does not show, image 3 shows, image 3 does not show, image 4 shows, image view does not show.... and do that for(int i -0; i < 8; i++).. Where can i do this? and how?, i was told i needed threads.. but i am new to Android and I am not sure how to do it :(
Thank you in advance
if I understand your question correctly you're not looking for them to animate, right? You just want the drawable of the image to change from 1 to n every time you press it?
In that case you won't need threads. Just make an array of your drawables and keep track of which one you're currently pointing to and set the background of your image to the currently indexed one as you click it. You don't need 4 imageViews in your xml (you need only one)... if I understand what you're actually doing :)
EDIT
Oh... you should have said something about simple simon, I would have immediately understood...
Ok, in that case you will need a an animation thread, but not so much to change the images (though that will also be part of it) but rather to set a timer so that when the computer plays its color patter for the player, it can sit on each color for some time and allow the player to memorize it.
Then you'll want to allow the player to press the colors and have the color "highlight" while they're on the color (and reset when they're off).
I'm not sure what your intention is with your isUser loop but that's definitely wrong (no matter what you're doing). And while your intention of sleeping is on the right track, you can't sleep in your main thread.
the way to handle this is to start a thread in the touch handler that sleeps for x milliseconds and then does your post sleep task. But you don't want to do any of that in a loop... just build an onTouchListener and pass it to each of your four buttons.
精彩评论