显示 Android 联系人的最佳实践 +电话号码

发布于 2024-11-25 04:44:21 字数 201 浏览 2 评论 0原文

从性能角度来看,显示包含联系人及其电话号码的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

屌丝范 2024-12-02 04:44:21

在我看来,混合解决方案应该更好。 为什么会这样?因为您不知道或者假设在大多数情况下您无法知道您的应用程序需要列出的联系人方式和数量。以及手机中存储了多少联系人。如果我们知道这两个答案,我们当然可以采取最接近的解决方案。

因此,我建议您首先在后台线程中使用内存数组带来固定数量的联系人,例如前 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.

就是爱搞怪 2024-12-02 04:44:21

我认为这取决于三个因素:

  1. 我们在这里谈论的联系人有多少?
  2. 加载每个联系人需要多长时间? (例如,您是否有一个需要膨胀的非常复杂的视图,或者您是否获取需要任何网络 I/O 的联系人图像/等?)
  3. 一次向用户显示多少联系人?

您的解决方案之一适合大多数情况,但第二种解决方案也提供了一些优点:

解决方案 1:

优点:

  1. 当“随行查看”中的延迟视图膨胀在足够快地膨胀视图且没有任何明显的 UI 时可以表现良好故障。

缺点:

  1. 如果您的联系人与大量数据关联并且需要一些复杂的膨胀,您可能会注意到延迟。

  2. 与解决方案 2 相比,灵活性和可扩展性较差。如下所述。

解决方案 2:

优点:

  1. 您可以控制所有步骤,因此您可以轻松地模拟它,就像模拟一样简单,但添加内容可能会更容易:搜索整个内存、自定义数组排序等。当您这样做时,它们会更好地工作将所有内容查询到已经存在的数组中。或者,如果您想稍后进行自定义加载,或者添加更多有关需要更多处理(例如网络 I/O)的联系人的数据,它可能比光标适配器稍微容易一些。

缺点:

  1. 执行:这不是教科书上执行的方法。使事情变得更加定制将需要您很好地处理所有线程并处理好初始外观。确保它可以扩展。

所以,是的,根据您到底在做什么,选择合适的。

I think this would depend on three factors:

  1. How many contacts are we talking about here?
  2. How much time does it take to load each contact? (E.g. do you have a very complicated view that needs to be inflated or do you fetch contact images/etc that requires any network I/O?)
  3. How much contacts are showing to the user at once?

Your solution one would fit most of the cases though the second solution offers some advantages as well:

Solution 1:

Advantage:

  1. Delayed view inflation in a "view as you go" can perform well when it's fast enough to inflate the views without any noticeable UI glitches.

Disadvantage:

  1. If your contacts associate with a lot of data and requires some complicate inflation, you might notice a delay.

  2. Less flexible and extensible comparing to solution 2. As discussed below.

Solution 2:

Advantage:

  1. You have control of all the steps, so you can easily simulate it just as easy as one, but adding things might be easier: searches through whole memory, custom sorting through the array, etc. they work better when you have everything queried to an array that's already there. Or if you want to do custom loading later, or adding some more data regarding the contacts that require some more processing (say network I/O), it might be slightly easier than cursor adapter.

Disadvantage:

  1. Execution: this is not the text-book way to do it. making things more custom will need you to handle all the threads well and handle the initial appearance well. Make sure it scales.

So yea, depending on what exactly are you are working on, choose the appropriate one.

爱的那么颓废 2024-12-02 04:44:21

我认为 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...

熟人话多 2024-12-02 04:44:21

我认为 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文