问题
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