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