在实现ArrayAdapter
的{{1}}内部,有代码检查以相同的第一个字母开头的列表项 - 因此可以合并。
像这样:
SectionIndexer
我的问题,是否以这种方式整合FastScrolling?有时在使用 alphaIndexer = new HashMap<String, Integer>();
int size = objects.length;
for (int i = 0; i < size; i++) {
// Log.d("ObjectLength", String.valueOf(objects.length));
ItemObject it = objects[i];
String name = it.name;
String s = name.substring(0, 1);
s = s.toUpperCase();
if (!alphaIndexer.containsKey(s)) {
alphaIndexer.put(s, i);
}
}
Set<String> sectionLetters = alphaIndexer.keySet();
ArrayList<String> sectionList = new ArrayList<String>(sectionLetters);
Collections.sort(sectionList);
sections = new String[sectionList.size()];
// sectionList.toArray(sections);
for (int i = 0; i < sectionList.size(); i++)
sections[i] = sectionList.get(i);
的ListViews上,快速滚动并不总是平滑但是“不连贯”。我可以从情况中移除SectionIndexer
,快速滚动会突然按比例平滑滚动。
添加代码:
SectionIndexer
答案 0 :(得分:5)
SectionIndexer确实会影响快速滚动。
使用SectionIndexer时,您说您希望用户能够精确地跳转到数据集的这些部分。如果这些部分中的数据分布不均匀,则快速滚动器将通过该组部分与其进度成比例地移动,而不是与通过数据集中的每个单独项目的进度成比例。
这是故意的;它以这种方式完成,这样当用户拖动快速滚动拇指时,每个部分的权重相等。准确定位任何部分就像定位任何其他部分一样简单,即使一个部分只有一个项目,并且其两侧的部分都有数百个。