android - getPositionForSection 和 getSectionForPosition 的区别

标签 android listview sectionheader

我正在实现 ListView 部分,其中我将自定义部分标题与传统字母表分开显示为标题。为了正确实现自定义 SectionIndexer,我想了解 getSectionForPositiongetPositionForSection 这两种方法之间的区别。

我理解(不确定这是否正确)getSectionForPosition 返回我们想要在节标题中显示的字母表。

我不明白另一种方法。此外,它们在任何意义上是否相似(如果有的话)以及它们有何不同(如果有,我认为它们有 :) )

任何对此有所了解的人都可以对此发表回答。感谢您花时间回答这个问题。

更新:

我已经阅读了这个 official page 的文档;我正在寻找关于自定义 SectionIndex 实现

的一些详尽的见解

最佳答案

getPositionForSection(section) 返回索引列的游标数据以该部分开始的第一个位置。

例如B段的索引为1,游标的索引列有如下数据

Position        Data               getSectionForPosition(position)

_________       __________         ______________________________

0               Abhfdf              0

1               Achahtkh            0

2               Ahtjlarej           0

3               Bchatkd             1

4               Bjklhdsfoi          1

5               Bzhafdlsfk          1

6               Cj fadsfkj          2

然后 getPositionForSection(1) 返回 3

同时 getPositionForSection(2) 返回 6

希望对你有帮助

关于android - getPositionForSection 和 getSectionForPosition 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12457518/

相关文章:

android - 我是否被迫使用 Android notifyChange() 方法?

objective-c - 获取分组 UITableView 中单元格的宽度以设置节标题宽度

ios - 点击其他节标题时重新加载节标题

java - Android ArrayAdapter NullPointerException getID

android - ListView onItemClick 从数据库中获取行?

java - 滚动 ListView 时 TextView 中的数据切换

安卓 : ListView get jumbled up while trying to write ViewHolder class for ListView with Section Headers

android - 如何修复错误 (1, -2147483648)

java - ListPreference 和翻译

android - 更改安卓 :installLocation from auto to internalOnly can lead to Play Store error 963