开发者

How do you update the screen after you change the text with a setText?

开发者 https://www.devze.com 2023-01-16 01:32 出处:网络
Right now I am using the following code to update a TextView txtMain.setText(\"new text\"); After that code executes, the screen does not update with the new text. I开发者_C百科s there a way I can

Right now I am using the following code to update a TextView

txtMain.setText("new text");

After that code executes, the screen does not update with the new text. I开发者_C百科s there a way I can force the text to update right then and there?


After that code executes, the screen does not update with the new text

It should, once you return control to Android.

Suppose, for example, you tried doing a Thread.sleep(5000); immediately after the setText() call. The text will not appear on the screen, because Android's main application thread is tied up sleeping and cannot redraw the screen.

So, make sure that you return from whatever callback you are in (onCreate(), onClick(), onListItemClick(), etc.), and Android should update the screen momentarily.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号