从套接字连接更新视图
我正在编写一个应用程序,需要每 10 秒左右从套接字接收数据,然后在屏幕上绘制一个视图以绘制该数据。不幸的是,我对 Android 还很陌生,并且在理解如何使其工作方面遇到一些困难。我一直在阅读一些有关处理程序的文章,但我不太确定如何使用它们。您可以将它们与扩展视图的类一起使用,还是我根本不需要使用它们?
I'm writing an application that needs to receive data from a socket every 10 seconds or so, and then draw a view on the screen to graph that data. Unfortunately, I'm pretty new to Android and am having some trouble understanding how to make this work. I've been doing some reading on handlers, but I'm not quite sure how to make use of them. Can you use these with a class that extends a View, or do I not need to use these at all?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用处理程序似乎是正确的方法,因为您正在从非 UI 线程更新 UI(至少您应该如此!)...您可以像这样使用处理程序,或者从 Activity 进行数据处理并调用来自 Activity 中处理程序的 CustomView.draw() 。
Using a Handler seems to be the correct approach since you are updating your UI from a non UI thread (at least you should be!)...You can either use the Handler like this, or do the data processing from your Activity and call CustomView.draw() from a Handler in your Activity.