开发者

Thread vs. Adapter for backgroud tasks - which one to prefer and why?

开发者 https://www.devze.com 2022-12-19 18:37 出处:网络
As a total noob to android progr开发者_运维百科amming I was advised to make use of adapters and handlers in order to update a textview periodically rather than thread/sleep.

As a total noob to android progr开发者_运维百科amming I was advised to make use of adapters and handlers in order to update a textview periodically rather than thread/sleep. However, I wonder why! Any suggestions?


In Android, you can't update a UI widget outside of the UI thread, so Handler provides a way for a Thread to communicate with the UI. In this approach, you start your thread to generate the view data and pass it to the Handler via a Message. The handler then updates the UI according to the data you sent.

I'm not sure exactly where an adapter would fit into the equation, since those are typically used to connect some data with a view (e.g. ListView and ListAdapter).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号