显示 Android 联系人的最佳实践 +电话号码
从性能角度来看,显示包含联系人及其电话号码的 ListView 的最佳方法是什么?
- 将 CursorAdapter 与联系人光标一起使用,并在为每一行调用 bindView 时进行电话号码查询。
- 将所有联系人和电话号码复制到后台线程中的内存数组中,然后使用 ArrayAdapter 显示它们。
- 其他解决方案?
What is the best approach from a performance perspective to show a ListView with contacts and their phone numbers?
- Use CursorAdapter with the contacts cursor and make the phone numbers query when bindView is invoked for each row
- Copy all the contacts and phone numbers to an in-memory array in a background thread and then show them with an ArrayAdapter.
- Other solutions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在我看来,混合解决方案应该更好。 为什么会这样?因为您不知道或者假设在大多数情况下您无法知道您的应用程序需要列出的联系人方式和数量。以及手机中存储了多少联系人。如果我们知道这两个答案,我们当然可以采取最接近的解决方案。
因此,我建议您首先在后台线程中使用内存数组带来固定数量的联系人,例如前 20 个。此外,如果您认为您的应用程序将对此服务执行多个请求..它将是使用某种缓存真是太棒了。最糟糕的方法应该是一次又一次地致电联系人服务。
然后,如果请求联系#21,您可以携带接下来的 20 个,依此类推。
因此,您可以利用两个世界的优点,并最大限度地减少缺点。始终取决于我们正在讨论的应用程序和上下文。
In my opinion a mix solution should be better. Why this? Because you don't know or it's suppose that in most of contexts you cannot know about how and how many contacts your application will need to list. An also how many contacts are stored in the phone. If we know both answers, surely we can take the most approach solution.
So I suggest you to first bring a fix number of contacts using an in-memory array in a background thread, for example the first 20. Also if you consider that your app will perform more than one request to this service.. it will be awesome to use a sort of caching. The worst approach should be to call again and again the contacts service.
Then for a request for contact #21 you can bring next 20 and so on.
So you can use the advantages of both worlds, and minimize the disadvantages too. Always depends on the application and the context that we are talking about.
我认为这取决于三个因素:
您的解决方案之一适合大多数情况,但第二种解决方案也提供了一些优点:
解决方案 1:
优点:
缺点:
如果您的联系人与大量数据关联并且需要一些复杂的膨胀,您可能会注意到延迟。
与解决方案 2 相比,灵活性和可扩展性较差。如下所述。
解决方案 2:
优点:
缺点:
所以,是的,根据您到底在做什么,选择合适的。
I think this would depend on three factors:
Your solution one would fit most of the cases though the second solution offers some advantages as well:
Solution 1:
Advantage:
Disadvantage:
If your contacts associate with a lot of data and requires some complicate inflation, you might notice a delay.
Less flexible and extensible comparing to solution 2. As discussed below.
Solution 2:
Advantage:
Disadvantage:
So yea, depending on what exactly are you are working on, choose the appropriate one.
我认为 http://www.higherpass.com/Android/Tutorials/ Work-With-Android-Contacts/ 将是一个选项。在这里您可以找到您想要的所有设施...
I think http://www.higherpass.com/Android/Tutorials/Working-With-Android-Contacts/ will be an option. Where you can find all of the facility you want...
我认为 CursorAdapter 是最好的解决方案。
另请务必观看此视频http://www.youtube.com/watch?v=wDBM6wVEO70< /a>
它讨论了我认为对于使列表平滑滚动所必需的优化。
I think CursorAdapter is the best solution.
Also make sure you watch this video http://www.youtube.com/watch?v=wDBM6wVEO70
It talks about optimizations that in my opinion are necessary to make your list scroll smoothly.