2011-07-15 18 views
5

我試圖用AlphabetIndexer實現一個快速滾動,但是當光標發生變化時,它不刷新索引chache。在我的CursorAdapter構造我叫setCursor(cursor)但沒有什麼變化,acording的文檔:AlphabetIndexer setCursor不更新其緩存

你的適配器負責通過調用 的setCursor(光標)如果光標變爲更新的光標。 getPositionForSection(int) 方法執行給定 節(字母)的起始索引的二進制搜索。

但是什麼都沒有發生。我使用它作爲搜索過濾器,所以當我搜索聯繫人時,它會使用聯繫人更新列表,因此AlphabetIndexer應該用於更新列表中新項目的索引。

示例:我的整個列表以以'A'開頭並以'E'開頭的聯繫人開始。因此,AlphabetIndexer將在其緩存中使用此索引。

但是,讓我們嘗試用'C'搜索聯繫人,並假設我有250個以'C'開頭的聯繫人。因此,我必須快速滾動瀏覽這些聯繫人,並且'C'索引必須顯示,但不是隻顯示'C',而是顯示所有索引,這些索引在我擁有整個列表時顯示。

這裏是我的CursorAdapter的構造,我打電話的setCursor(光標)對每一個字母I型:

public MyCursorAdapter(Context context, Cursor cursor, ArrayList<Integer> ids) 
     { 
      super(context, cursor); 
      try 
      { 
       mAlphaIndexer = new AlphabetIndexer(cursor, cursor.getColumnIndexOrThrow("Name")," ABCDEFGHIJKLMNOPQRSTUVWXYZ"); 
       notifyDataSetChanged(); 
       mAlphaIndexer.setCursor(cursor);   
       this.mSelectedContacts = ids;    
       Log.e("MyCursorAdapter", "construtor: "); 
      } 
      catch(Exception ex) 
      { 
       Log.e("MyCursorAdapter", "Error: " + ex); 
      } 
      finally 
      { 
       mAlphaIndexer.setCursor(cursor); 
      } 
     } 
+0

我在做類似的東西這裏http://stackoverflow.com/questions/10224233/alphabetindexer-with-custom-adapter-managed-by-loadermanager – toobsco42

回答

3

我已經在程序調用這個解決了這個之後,我將適配器設置:

listView.setFastScrollEnabled(false); 
listView.setFastScrollEnabled(true); 

這對我有用。

+1

這不適用於KITKAT :) –

0

請致電setContentView(R.layout.whatever),然後用新的適配器/新數據項重新填充ListView。這將使用新項目重繪ListView,並且FastScroll疊加層將出現在正確的位置。