I'm working on an app using android studio, and I need to delay in before the text changes, this is the part of code that needs a delay:
public void sleep(int time) {
try {
// Thread.sleep(time);
// TimeUnit.SECONDS.sleep(time);
// Thread.wait(time);
} catch (Exception e) {}
}
public void MoveOn() {
UsAnswer = Integer.parseInt(Input.getText().toString());
if (UsAnswer != cran) {
feedback.setTextColor(Color.RED);
feedback.setText("✖");
// Wait 2 seconds
sleep(2);
feedback.setText("");
Input.setText("");
} else {
feedback.setTextColor(Color.GREEN);
feedback.setText("✔");
// Wait 2 seconds
sleep(2);
feedback.setText("");
MainLoop();
}
}
As you can see, in my sleep function (at least I think they're called functions in Java ) I used three different sleep methods.
However, they all pause the whole GUI, I just need it to wait two seconds, showing the earlier action feedback.setText("✖");
& feedback.setText("✔");
.
I read on this post that I should use a Swing Timer, but wasn't sure how. To be honest (being a beginner) I have no idea what a Swing Timer is .
PS: If you do answer my question, then please don't take my code and modify it so that it will work perfectly, just give me the code and show me how to use it. That way I won't be lazy and just copy/paste, and also, that way I'll learn .