列表视图随时间更新
我正在编写一个世界时钟应用程序,其中使用自定义列表视图和适配器。我显示了城市及其时间的列表。问题是我想随着时间的流逝不断更新视图中显示的每个城市的时间。我该怎么做?
I am writing a world clock application in which I am using a custom list view and adapter. I show a list of cities and their times. The problem is I want to keep updating the time for each city shown in the view, as the seconds pass. How should I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您为列表视图设置了适配器,则可以更新适配器数据集并通知视图更改,请参阅此 api:notifyDataSetChanged()。但因为它每秒更新一次。我不确定这种方法在性能方面是否有效。
If you have the adapter set up for the listview, you can update the adapter data set and notify the view of changes, see this api: notifyDataSetChanged(). but since it is updating every sec. I am not sure this method is efficient in terms of performance.
跟踪用于显示各个时间的视图没有帮助,因为视图是
重用 - 最好的选择是通知列表数据集已更改,并更新各个视图。如果您小心并重复使用城市视图,视图更新量将会很低。
Keeping track on views used to display individual times would not help, as views are
reused - your best bet is to notify list that dataset is changed, and update individual views. If you take care and reuse city views, amount of view updates will be low.