
지금 위의 그림처럼 리스트들을 ㄱㄴㄷ순으로 정렬하여 스크롤을 끌 때 초성이 ㄱ인지 ㄴ인지를 보여주기 위해 커스텀 adapter에 sectionIndexer를 implements했습니다.
그냥 ListView일때는 문제가 없었는데 ExpandableListView에서는 문제가 생깁니다.
예를 들어 위 그림처럼 버벌진트를 클릭해 Child가 하나가 생기면 순서가 하나씩 밀려 신용재에서 'ㅅ'이 떠야함에도
'ㅂ'이 떠버립니다.
아래는 SectionIndexer 관련합수입니다.
@Override
public int getPositionForSection(int section) {
// TODO Auto-generated method stub
int _section;
String letter = (String)sections[section];
_section = myIndexer.get(letter);
return _section;
}
@Override
public int getSectionForPosition(int position) {
Log.d(TAG, "position : "+position);
// TODO Auto-generated method stub
int _position=position;
int closestIndex = 0;
int latestDelta = Integer.MAX_VALUE;
for (int i = 0; i < sections.length; i++) {
int current = myIndexer.get(sections[i]);
if (current == _position) {
// If position matches an index, return it immediately
return i;
} else if (current < _position) {
// Check if this is closer than the last index we inspected
int delta = _position - current;
if (delta < latestDelta) {
closestIndex = i;
latestDelta = delta;
}
}
}
Log.d(TAG, "closestIndex : "+sections[closestIndex]);
return closestIndex;
}
@Override
public Object[] getSections() {
// TODO Auto-generated method stub
return sections;
}
진짜 구글링을 4일정도 하면서 방법을 찾아봤지만 해결이 되지않네요.
알파벳뿐만 아니라 한글까지 들어가서 stackoverflow의 답변을 사용해도 잘 되지 않았습니다.
혹시 방법을 아시는 분이 있으면 꼭 좀 알려주시면 감사하겠습니다.