简体   繁体   English

具有实时传感器更新的android listview

[英]android listview with real-time sensor updates

I am working on a app that shows some places in a listview. 我正在开发一个显示列表视图中某些位置的应用程序。 In every listview item there is a arrow pointing towards the place(hotel, bar etc). 在每个listview项目中都有一个指向该地方的箭头(酒店,酒吧等)。

The problem is I don't know how to keep this arrow updated efficiently, without cashing views locally( which, according to a Google I/O video, is something i should never ever do). 问题是我不知道如何有效地更新此箭头,而无需在本地兑换视图(根据Google I / O视频,这是我永远不应该做的事情)。

The arrow needs to be updated on every phone orientation sensor event, which is many times a second. 需要在每个手机方向传感器事件上更新箭头,该事件是每秒多次。

So is there a better approach than calling notifyDataSetChanged() on every event and refiling every list item data? 那么有没有比在每个事件上调用notifyDataSetChanged()并重新编译每个列表项数据更好的方法?

UPDATE (for @dharan and anyone interested): 更新 (对于@dharan和任何感兴趣的人):

I have stopped working on this project because I have a full-time job now, but I thought of a solution (unimplemented/untested). 我已经停止了这个项目,因为我现在有一份全职工作,但我想到了一个解决方案(未实现/未经测试)。

First limit the angle of rotation to a fixed step, (eg: 5, 10, 15, 20, ... 355, 360) then cache the rotated image for each angle of rotation in order to avoid expensive image rotation calculations (but at a higher memory cost). 首先将旋转角度限制为固定步长(例如:5,10,15,20,... 355,360)然后缓存每个旋转角度的旋转图像,以避免昂贵的图像旋转计算(但是在更高的内存成本)。

After that I would make my getView() method know when to only update the image instead of all the data. 之后我会让我的getView()方法知道何时只更新图像而不是所有数据。 In my case this is as easy as: 就我而言,这很简单:

public View getView(int position, View convertView, ViewGroup parent) {
     if (convertView != null && place[position].id == (Integer)convertView.getTag()){
         //the place information is already set correctly so just update the image
     }
     ...
}

After these modifications I believe that calling notifyDataSetChanged() should not cause serious performance issues. 经过这些修改后,我认为调用notifyDataSetChanged()不应该导致严重的性能问题。

If you don't have too many items in the ListView you could convert to using a plain LinearLayout and control those items individually. 如果ListView中没有太多项目,您可以转换为使用普通的LinearLayout并单独控制这些项目。 The problem with LinearLayout though is if an item changes its size then everything (ie all children) has to be relayed out. 但是,LinearLayout的问题是,如果某个项目的大小发生变化,那么所有内容(即所有子项)都必须被中继。 So triggering a change in one item can re-trigger other things to layout as well. 因此,触发一个项目的更改也可以重新触发其他布局。 Now because you're changing a compass needle you might be able to skirt around it because that shouldn't cause each row to change its overall size. 现在,因为你正在更换罗盘针,你可以绕过它,因为这不应该导致每一行改变它的整体尺寸。 You just need to repaint that item. 你只需要重新绘制该项目。

The other option is to write your own layout that takes some short cuts making some assumptions the general purpose layout managers can't. 另一个选择是编写自己的布局,采取一些捷径,做出一些假设,通用布局管理器不能。 The last thing I might look at is what does notifyDataSetChanged() does under the covers. 我可能会关注的最后一件事是notifyDataSetChanged()做了什么。 You might be able to extend ListView and write a method that only redraws the row that changed (of course this assumes the height of the row hasn't changed). 您可以扩展ListView并编写一个只重绘已更改行的方法(当然这假设行的高度没有改变)。 If the row height changes then everything after that row has to be relayed out. 如果行高度发生变化,那么该行之后的所有内容都必须被中继。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 实时Excel更新 - Real-Time Excel Updates 基于通知的实时PostgreSQL客户端更新 - Real-Time PostgreSQL client updates based on notification 如何监听 Firestore 中文档列表的实时更新? - How to listen for real-time updates on a list of documents in Firestore? Android套接字:实时接收数据 - Android sockets: receiving data in real-time 实时显示时间并在列表视图中更新 - Displaying time in real-time and updating within a listview 使用Json时可以实时更新Listview吗? - Is it possible to update a Listview on real-time when we use Json? 如何将列表视图中我从 Firebase 实时数据库中调用的数据移动到 android 工作室中的另一个活动? - How to move the data that I have called from the Firebase real-time database, in a listview to another activity in android studio? 当时间比较评估为真时,如何实时更新 Java 中的 Excel.csv 文件? - How to make real-time updates of an Excel .csv file in Java when time comparison evaluates as true? Android-跟踪要绘制的实时触摸事件 - Android - Tracking Real-Time Touch Events to Draw Android Studio:有没有办法实时查看所有文件? - Android Studio: Is there a way to see all the files executed in real-time?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM