开发者

AlphabetIndexer setCursor doesn't update its cache

I'm trying to implement a fast scroller with AlphabetIndexer, but when the cursor changes, its not refreshing the index chache. In my CursorAdapter constructor I call setCursor(cursor) but nothing changes, and acording to the documentation:

Your adapter is responsible for updating the cursor by calling setCursor(Cursor) if the cursor changes. getPositionForSection(int) method does the binary search for the starting index of a given section (alphabet).

But nothing is happening. I'm using this for a search filter, so when I search contacts, it updates the list with the contacts, so AlphabetIndexer should work for update the index of the new items in the list.

Example: My whole list starts with contacts that starts with 'A' and ends with contacts that starts with 'E'. So the AlphabetIndexer will have this indexes in its cache.

But, lets try to search contacts with 'C', and lets say I have 250 contacts that starts with 'C'. So, I have to fast scroll through this contacts, and the 'C' index must show, but instead of only 'C' it shows all indexes, that were shown when I had the entire list.

Here is my CursorAdapter constructor where I call setCursor(cursor) for every letter I type:

p开发者_如何学Cublic 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);
            }
        }


I've solved this by calling this in sequence after I set the adapter:

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

That worked for me.


call setContentView(R.layout.whatever)and then re-populate the ListView with your new adapter / new data items. This will redraw the ListView with your new items and the FastScroll Overlay will appear in the correct place.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜