I'd like to do setText() on a TextView and make the activity sleep just after.
Here is the code :
tv.setText("myText");
tv.invalidate(); // Doesn't work
pause(1000); // French for sleep
And my function pause :
public void pause(int seconds)
{
synchronized(this)
{
try {
this.wait(seconds);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
}
}
The problem is that the TextView doesn't update before sleeping. I tried to call invalidate() on my TextView but it doesn't work.
I have another possible solution : create a new Thread for sleeping the activity, and if the value of my TextView is still the same, reload the Thread, else call my function pause(). But is it possible to get the real value of my TextView in the View ? Because I can get the new text when I do :
tv.setText("myText");
System.out.println(tv.getText());
pause(1000); // French for sleep
Whereas the text doesn't update in the View.
Any idea ?
I would suggest what Jave said.
tv.setText("myText");
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
//Do something
}
}, 3000); //3000 is time in ms.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With