Android自定义光标适配器和BindView
好吧,我希望我不会因为问这样一个模棱两可的问题而受到批评,但我很困惑,甚至不知道如何问这个问题。我将尽力传达我的问题,并在需要时进行澄清。
我有两个使用 MergeCursor 合并的游标。我还有一个自定义光标适配器。在我的自定义光标适配器中,我重写了 BindView。我注意到奇怪的行为,项目没有显示在我的列表视图中。本质上,列表视图中的每一行都有两个文本视图。最后一行中有一个字段为空。
我单步执行 BindView,发现它被执行了 3 次。我的列表视图中只有 7 个项目(即 7x3)。除第 7 项中的一个字段外,所有这些都显示在屏幕上。我注意到,在两次通过 BindView 时,缺少一个字段值。
我想知道的是,为什么BindView执行了3次。所以当我说 3 时,我的意思是 3x7。列表中有 7 个项目,因此 BindView 循环了 21 次。我希望我说得有道理。
如果这不清楚,请不要攻击我。我很乐意修改或提供附加信息。
Ok, I hope I don't get slammed for asking such an ambiguous question but I am stumped and don't even know how to ask this. I am going to try as best as possible to communicate my problem and will clarify if needed.
I have two cursors merged using MergeCursor. I also have a custom cursor adapter. In my custom cursor adapter I have overridden BindView. I am noticing strange behavior where items are not showing up in my listview. Essentially I have two textviews for each row in the listview. In the last row one of the fields is empty.
I step through the BindView and I notice it gets executed 3 times. My listview only has 7 items in it (so that's 7x3). All of them show on the screen except one of the fields in item 7. I notice that on two passes though BindView a field value is missing.
What I want to know is, why is BindView executing 3 times. So when I say 3 I mean 3x7. 7 items in the list, so it cycles through BindView 21 times. I hope I'm making sense.
Please don't slam me if this is not clear. I am happy to modify or provide additional info.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当 ListView 进入测量阶段时,它将在适配器上调用 newView 和 bindView,以便它可以设置行(其子项)的尺寸并确定其自己的尺寸。在此过程中,它不会保留视图,因此在屏幕上绘制视图时需要重新创建视图。您可以查看 ListView 源代码,以便准确查看它在做什么。
When ListView goes trough the measure phase, it will call newView and bindView on your adapter so it can set the dimensions of the rows (its children) and determine it's own dimensions. In the process, it doesn't retain the views, so they need to be recreated when the views are drawn on the screen. You can look at the ListView source so see exactly what it's doing.