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

跟風遠走 提交于 2019-12-11 00:19:28

问题


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. Is there a way I can force the text to update right then and there?


回答1:


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.



来源:https://stackoverflow.com/questions/3695993/how-do-you-update-the-screen-after-you-change-the-text-with-a-settext

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!