在ArrayAdapter
实现内部SectionIndexer
有代码检查以相同的第一个字母开头的列表项 - 因此可以合并它。
像这样:
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);
我的问题是,合并这种方式会影响 FastScrolling 吗?有时在使用 的 ListViews 上SectionIndexer
,Fast Scroll 并不总是流畅,而是“断断续续”。我可以SectionIndexer
从情况中删除,快速滚动突然平滑且按比例滚动。
添加代码:
public int getPositionForSection(int section) {
return alphaIndexer.get(sections[section]);
}
public int getSectionForPosition(int position) {
return 0;
}
public Object[] getSections() {
return sections;
}