3

안드로이드에서 SectionIndexerGridView을 사용할 수 있습니까? 빠른 스크롤이 제대로 작동하고 있으며 BaseAdapter까지 확장되는 맞춤형 어댑터를 사용하고 있습니다. 어댑터는 현재 SectionIndexer을 구현하고 있으며 온라인 및 스택 오버플로에 표시된 예제와 동일합니다. 이것은 내가 GridView과 맞춤형 어댑터로 할 수 있다고 생각하게 만들었다.안드로이드에 GridView가있는 SectionIndexer

+0

물론 '커서'를 사용하여 데이터를 정렬하는 한 가능합니다. – adneal

+0

커서를 사용하고 있지 않습니다. ArrayList에 저장되어 있지만 Cursor로 변경할 수 있다고 가정합니다. 커서를 사용하는 예제가 있습니까? –

+0

최상의 샘플 https://github.com/guoGavin/Andorid-StickyHeaderGridView –

답변

3
static class YOUR_ADAPTER extends SimpleCursorAdapter implements SectionIndexer { 

private AlphabetIndexer mIndexer; 

YOUR_ADAPTER (Context context, AlbumBrowserActivity currentactivity, 
      int layout, Cursor cursor, String[] from, int[] to) { 
     super(context, layout, cursor, from, to); 

     getColumnIndices(cursor); 
    } 

    private void getColumnIndices(Cursor cursor) { 
     if (cursor != null) { 
      YOUR_COLUMN = cursor.getColumnIndexOrThrow(WHAT_YOU'RE_SORTING); 

      if (mIndexer != null) { 
       mIndexer.setCursor(cursor); 
      } else { 
       mIndexer = new AlphabetIndexer(cursor, YOUR_COLUMN, mResources.getString(
         R.string.fast_scroll_alphabet)); 
      } 
     } 
    } 

    @Override 
    public Object[] getSections() { 
     return mIndexer.getSections(); 
    } 

    @Override 
    public int getPositionForSection(int section) { 
     return mIndexer.getPositionForSection(section); 
    } 

    @Override 
    public int getSectionForPosition(int position) { 
     return 0; 
    } 
} 

기본적인 예,하지만 그것보다 훨씬 더 많은 것이 아니다 fast_scroll_alphabet String

<string name="fast_scroll_alphabet">\u0020ABCDEFGHIJKLMNOPQRSTUVWXYZ</string> 

. SectionIndexer을 구현하는 것은 매우 간단합니다.

+0

AlphabetIndexer가 누락되었습니다 :-) –

관련 문제