AlphabetIndexer setCursor 不更新其缓存
我正在尝试使用 AlphabetIndexer 实现快速滚动器,但是当光标更改时,它不会刷新索引缓存。在我的 CursorAdapter 构造函数中,我调用 setCursor(cursor) ,但没有任何变化,根据文档:
您的适配器负责通过调用来更新光标 setCursor(Cursor) 如果光标发生变化。 getPositionForSection(int) 方法对给定的起始索引进行二分搜索 部分(字母)。
但什么也没发生。我将其用于搜索过滤器,因此当我搜索联系人时,它会使用联系人更新列表,因此 AlphabetIndexer 应该用于更新列表中新项目的索引。
示例:我的整个列表以“A”开头的联系人开始,以“E”开头的联系人结束。因此 AlphabetIndexer 将在其缓存中包含此索引。
但是,让我们尝试搜索以“C”开头的联系人,假设我有 250 个以“C”开头的联系人。因此,我必须快速滚动浏览此联系人,并且必须显示“C”索引,但它不是仅显示“C”,而是显示所有索引,这些索引是在我拥有整个列表时显示的。
这是我的 CursorAdapter 构造函数,我为输入的每个字母调用 setCursor(cursor) :
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);
}
}
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:
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);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我通过在设置适配器后按顺序调用它来解决了这个问题:
这对我有用。
I've solved this by calling this in sequence after I set the adapter:
That worked for me.
调用 setContentView(R.layout.whatever),然后使用新适配器/新数据项重新填充 ListView。这将使用新项目重新绘制 ListView,并且 FastScroll Overlay 将出现在正确的位置。
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.