2012-04-30 12 views
3

GridViewをAndroidで使用することはできますか?ファストスクロールは正常に動作しており、私はBaseAdapterを拡張するカスタムアダプタを使用しています。アダプタは現在SectionIndexerを実装しており、オンラインとStack Overflowに示されている例と同じようです。これにより、GridViewとカスタムアダプターを使用することも可能であると考えられました。基本的な例ですが、はるかにそれまでよりもありませんAndroidでGridViewを使用しているSectionIndexer

+0

「Cursor」を使用してデータをソートしている限り、もちろん可能です。 – 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が欠けていました:-) –

関連する問題