Setting TextView visible from another thread or BeginInvoke in Android

与世无争的帅哥 提交于 2019-12-10 17:11:33

问题


I'm developing an Android 2.2 application.

I have an event listener on an activity, and I want to set visible a TextView when I receive an event. But there is an error:

I only can set it visible from UI thread.

In C# and Windows Mobile there is a BeginInvoke. Is there something similar in Android?

Thanks.


回答1:


You can use Activity#runOnUiThread or an AsyncTask as the two easiest ways to duplicate the BeginInvoke functionality; with runOnUiThread being the one most similar.

For more complicated or performance orientated needs (i.e., you do not want to keep creating a large number of Runnable objects) you can use a Handler. However, I do not recommend it as your first choice.



来源:https://stackoverflow.com/questions/4629169/setting-textview-visible-from-another-thread-or-begininvoke-in-android

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