android - View的post()方法的主要目的是什么

标签 android

与 imageview、textview 等 View 相关的 post 方法的主要用途是什么

new View(Context).post(runnable)

举个例子,我们将不胜感激:)

最佳答案

来自 API 文档:

Causes the Runnable to be added to the message queue. The runnable will be run on the user interface thread. This method can be invoked from outside of the UI thread only when this View is attached to a window.

看起来像:如果您想在另一个线程中更新 View ,您可以简单地使用 post 方法来更新 View 。虽然类型是runnable,但是它不能在单独的线程中运行,它会像调用普通方法一样在ui线程中运行。

关于android - View的post()方法的主要目的是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10220567/

相关文章:

android - 如何解决 "make: *** No rule to make target ` out/target/product/generic/root/file_contexts', `snod' 需要。停止。”

android - smoothScrollToPosition() 仅在 Android ICS 中滚动到一半?

Android EditText 提示

android - 在 java 代码中设置时,外部 View 的 LayoutParams 宽度被忽略(而不是 xml 布局)

android - 在文本输入布局android之外单击时如何将 float 标签文本重置为其原始位置

android - Admob:添加多个测试设备(ID)

android - react-native 包的原生部分可以独立运行和开发吗?

java - 在Android(使用Java)中,如何设置铃声音量(到指定的数字)?

android - onTextContextMenuItem 不会在自定义菜单项上调用

android - NME android 路径位置?