Khi FastScroller
(trong AbsListView
lớp ListView
kéo dài từ) có được phần của mình bằng cách gọi SectionIndexer#getSections()
, nó không bao giờ tái có được chúng trừ khi bạn bật/tắt nhanh chóng cuộn như đề cập trong liên kết mà bạn đề cập. Để có được giá trị được hiển thị trên màn hình, FastScroller gọi phương thức toString của phần.
Một giải pháp tiềm năng là phải có một tùy chỉnh SectionIndexer
có các đặc điểm sau:.
- Mảng phần là có độ dài cố định (chiều dài tối đa của số lượng dự kiến của phần Ví dụ, nếu các phần đại diện cho tiếng Anh bảng chữ cái nó sẽ là 26)
- Có một đối tượng tùy chỉnh để biểu diễn các phần thay vì sử dụng các chuỗi
- Ghi đè phương thức
toString
của đối tượng phần tùy chỉnh để hiển thị những gì bạn muốn dựa trên 'giá trị phần' hiện tại. -
ví dụ: Trong tùy chỉnh của bạn SectionIndexer
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";
}
}
Tôi đang làm một cái gì đó tương tự ĐÂY http://stackoverflow.com/questions/10224233/alphabetindexer-with-custom-adapter-managed-by-loadermanager – toobsco42