I want to make a simple game, with one image view and two buttons to guess if the card is red of black.
I want to use a thread, for every 0.1 seconds before the player presses the button, the card is changing.
this is what i used so far :
Thread timer = new Thread() {
public void run() {
while (true) {
try {
if(!isInterrupted())
sleep(100);
else
sleep(5000);
runOnUiThread(new Runnable() {
@Override
public void run() {
if(!isInterrupted()) {
if (iv_card_to_Guess.getDrawable() == null)
iv_card_to_Guess.setImageBitmap(deck_card);
else
iv_card_to_Guess.setImageDrawable(null);
}
else {
//here need to update imageview with the actual image of the card, not just the deck or null
// for example 5 of Hearts
loadBitmap(getResourceID("img_" + numbers.get(count).toString(), "drawable", getApplicationContext()), iv_card_to_Guess);
}
}
});
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
};
When i press a button i call timer.interrupt();
The application changes the image of the actual card but also for 0.1 seconds, not for 5 seconds, like i want :)
How can i do this, please?