答案 0 :(得分:4)
FastScroller
(AbsListView
类ListView
中的SectionIndexer#getSections()
类)通过调用SectionIndexer
获取您的部分后,除非启用/禁用,否则永远不会重新获取它们像你提到的链接中提到的快速滚动。要获取要在屏幕上显示的值,FastScroller会调用该部分的toString方法。
一个可能的解决方案是拥有具有以下特征的自定义toString
:
private int mLastPosition;
public int getPositionForSection(int sectionIndex) {
if (sectionIndex < 0) sectionIndex = 0;
// myCurrentSectionLength is the number of sections you want to have after
// re-indexing the items in your ListView
// NOTE: myCurrentSectionLength must be less than getSections().length
if (sectionIndex >= myCurrentSectionLength) sectionIndex = myCurrentSectionLength - 1;
int position = 0;
// --- your logic to find the position goes in here
// --- e.g. see the AlphabeticIndexer source in Android repo for an example
mLastPosition = position;
return mLastPosition;
}
public Object[] getSections() {
// Assume you only have at most 3 section for this example
return new MySection[]{new MySection(), new MySection(), new MySection()};
}
// inner class within your CustomSectionIndexer
public class MySection {
MySection() {}
public String toString() {
// Get the value to displayed based on mLastPosition and the list item within that position
return "some value";
}
}
方法,根据当前的“部分值”显示所需内容。e.g。在您的自定义SectionIndexer
中{{1}}
答案 1 :(得分:1)
我发现执行此操作的最佳方法是调用setContentView(R.layout.whatever)
,然后使用新的适配器/新数据项重新填充ListView
。这将使用您的新项目重新绘制ListView
,并且FastScroll Overlay将显示在正确的位置。
答案 2 :(得分:0)
我发现notifyDataSetInvalidated
工作正常,这就是想法:
public class MyAdapter extends XXXAdapter implements SectionIndexer {
...
public void updateDataAndIndex(List data, Map index) {
// update sections
// update date set
notifyDataSetInvalidated();
}
}
以某种方式更新您的数据集和索引(部分),然后notifyDataSetInvalidated
,索引将刷新。
答案 3 :(得分:0)
您可以通过listView.setAdapter(yourAdapter)