Inside ArrayAdapter
Implementing SectionIndexer
有代码检查以相同的第一个字母开头的列表项目 - 因此可以合并。SectionIndexer如何影响Android快速滚动?
像这样:
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?有时在使用SectionIndexer
的ListViews上,快速滚动并不总是平滑但“波涛汹涌”。我可以从这种情况中删除SectionIndexer
,快速滚动按比例顺利滚动。
添加的代码:
public int getPositionForSection(int section) {
return alphaIndexer.get(sections[section]);
}
public int getSectionForPosition(int position) {
return 0;
}
public Object[] getSections() {
return sections;
}
您发布的代码在每次调用getSectionForPosition' /'getPositionForSection'时执行? – zapl
@zapl我只是将这些方法添加到顶部,以便您可以看到我在做什么。 – KickingLettuce
http://stackoverflow.com/questions/11988886/fastscrollbar-go-out-of-screen-when-sectionindexer-实施 – GOLDEE