Android:何时使用Button.Post? [英] Android: When to use Button.Post?

查看:56
本文介绍了Android:何时使用Button.Post?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到Android的 Button 类中的一种名为 Post 的方法.我想知道这种方法是干什么用的?此方法带有一个可运行的参数,我的问题是,何时应该使用此方法而不是仅将侦听器绑定到此按钮的click事件?有什么区别?任何例子都表示赞赏.

I noticed a method called Post in Android's Button class. I was wondering what this method was for? This method takes a runnable argument, my question is when should we use this vs just having a listener bind to the click event of this button? What is the difference? Any example is appreciated.

推荐答案

post()继承自 View .它与按钮单击无关,并且不能代替 OnClickListener . post()用于安排 Runnable 在主应用程序线程上执行,通常由在后台线程上运行的某些代码执行.

post() is inherited from View. It has nothing to do with button clicks and is not a replacement for an OnClickListener. post() is used to arrange for a Runnable to be executed on the main application thread, typically by some code running on a background thread.

这篇关于Android:何时使用Button.Post?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆