I have some Buttons in my application and I need to change the text in them with 1 sec delay after every change. I've tried using Thread.sleep()
in the cycle but it works incorrect (all the buttons change the text at the same time). How can I solve this situation?
Asked
Active
Viewed 51 times
-3

Дмитрий Зыков
- 1
- 1
2 Answers
2
You can use this:
Handler handler = new Handler();
handler.postDelayed(new Runnable()
{ public void run() {
// Change button text
} }, 1000);

Zharin
- 75
- 12
0
You should not stop the main thread for that work. Create a separate thread or use Async task to do that work. You can use sleep() method in Async task and your main thread will not be affected. If you need code for that send the code you have tried till now.

Raj
- 2,997
- 2
- 12
- 30
-
For a short timer like that, posting a message to a Handler is usually used instead- a full Thread or AsyncTask is overkill, and would just be posting back to the UI thread anyway. – Gabe Sechan Jun 24 '18 at 18:05