问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/8717145/android-when-to-use-button-post