从Android的另一个线程或BeginInvoke的设置TextView中可见 [英] Setting TextView visible from another thread or BeginInvoke in Android
问题描述
我开发一个Android 2.2的应用程序。
I'm developing an Android 2.2 application.
我在一个活动的事件侦听器,我想设置可见一个TextView,当我收到一个事件。但有一个错误:
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:
我只能将它从UI线程可见。
I only can set it visible from UI thread.
在C#和Windows Mobile有一个BeginInvoke的。是否有类似的Android中的东西吗?
In C# and Windows Mobile there is a BeginInvoke. Is there something similar in Android?
感谢。
推荐答案
您可以使用<一个href=\"http://developer.android.com/reference/android/app/Activity.html#runOnUiThread%28java.lang.Runnable%29\"相对=nofollow> 活动#runOnUiThread
或一个的 的AsyncTask
以复制的BeginInvoke
功能两种最简单的方法;与 runOnUiThread
是一个最相似的。
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.
有关更复杂或性能导向的需求(比如,你不想保持造就了一大批的Runnable
的对象),您可以使用的 处理程序
。不过,我不推荐它作为您的第一选择。
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.
这篇关于从Android的另一个线程或BeginInvoke的设置TextView中可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!