使用IListDataAdapter进行ListView虚拟化 [英] ListView virtualisation with IListDataAdapter

查看:70
本文介绍了使用IListDataAdapter进行ListView虚拟化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从具有分页数据的服务中获取数据,给定页面大小为15个项目。这意味着我可以查询第1页,第2页......但是我无法指定要检索的起始项或项数。

I get data from a service that have paged data, with a given page size of 15 items. It means I could query page 1, 2, ... but I cannot specify the starting item or the number of items I want to retrieve.

我为列表视图创建了一个自定义数据源实现IListDataAdapter。我实现了将项目索引转换为page  number的管道,但我最终得到了一个无限循环调用itemsFromIndex。前两个调用看起来很好(请求索引0
和15),之后事情变得奇怪(再次为索引0调用 然后调用索引14,页面0的一部分,永远) 。

I made a custom datasource for a listview by implementing IListDataAdapter. I implement the plumbing for turning item index to page number but I end up with an infinite loop calling itemsFromIndex. The first two calls looks good (requesting index 0 and 15), and things get weird after that (a call for index 0 again, and then calls for index 14, part of page 0, forever).

我用Bing搜索样本进行了双重检查,我看不出我的错误(如果有的话),除了我不能提供与数据源要求的项目一样多的项目。我可以发送代码,如果它可以提供帮助(服务可在网上获得)。

I double checked with the Bing Search sample and I cannot see my mistake (if any), except that I cannot give as much items as the datasource asked. I could send the code if it could help (the services are available on the web).

推荐答案

编写数据适配器时的主要要求是确保返回索引要求的项目。 countBefore和countAfter是建议性的,因此您应该能够将请求的索引映射到您的某个页面,然后返回该页面的所有
数据。

The main requirement when writing a data adapter is to ensure that you return the item asked for by the index. The countBefore and countAfter are advisory, and so you should be able to map the requested index into one of your pages, and then return all the data for that page.

A要验证的事情:


  • 您正确设置偏移量 - 这是在请求的索引处的项目结果数组的偏移量
  • 您的密钥是唯一的,并且是字符串

 


这篇关于使用IListDataAdapter进行ListView虚拟化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆