如何对 SimpleCursorAdapter 支持的 Android ListView 进行文本过滤?
我有一个由 SimpleCursorAdapter 支持的 ListView。
我希望能够像过滤联系人列表一样过滤列表,只需键入,我遇到了 textFilterEnabled()
问题是,我不知道如何让它与 SimpleCursorAdapter 一起使用。
这可能吗?
如果是这样,是如何做到的?
I have a ListView that is backed by a SimpleCursorAdapter.
I'd like to be able to filter the list like you would a contacts list, just by typing, and I came across the textFilterEnabled()
Problem is, I couldn't see how to get it to work with a SimpleCursorAdapter.
Is this even possible?
If so, how is it done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于 SimpleCursorAdapter 游标,您只需要使用 setFilterQueryProvider 即可根据约束为游标运行另一个查询:
添加约束时(例如,通过使用 TextView)必须过滤适配器:
希望这会有所帮助。我将在接下来的几天里尝试写一篇完整的文章,并附上源代码。
For a SimpleCursorAdapter cursor, you only need to use the setFilterQueryProvider, to run another query for your cursor, based on the constraint:
When a constraint is added (eg. by using a TextView) the adapter must be filtered:
Hope this helps. I will try to write a complete article , with source code the next few days.
setTextFilterEnabled()
方法不会自动实现过滤,因为它不知道您的Cursor
中的文本应针对哪些内容进行过滤。此 android 开发者帖子提供了更多详细信息。
其实前几天有人问了一个很好的问题,其实和你的问题很相似;尽管它最初是询问当设备上没有物理键盘时如何处理过滤:
The
setTextFilterEnabled()
method doesn't automatically implement filtering, as it doesn't know what in yourCursor
the text should be filtered against.This android-developers thread has more details.
Actually, there was a good question asked the other day, which actually is very similar to your question; though it originally was asking how to handle filtering when there is no physical keyboard on a device:
我发现这篇文章很有帮助http://androidcookbook.oreilly.com/Recipe。 seam;jsessionid=CE37400B3E545937B70BE2E9F94E78BB?recipeId=404
基本上,您在列表视图上
setTextFilterEnabled(true)
,然后使用setStringConversionColumn()
和setFilterQueryProvider( )
在您的SimpleCursorAdapter
上。i found this article helpful http://androidcookbook.oreilly.com/Recipe.seam;jsessionid=CE37400B3E545937B70BE2E9F94E78BB?recipeId=404
basically, you
setTextFilterEnabled(true)
on your listview, and you usesetStringConversionColumn()
andsetFilterQueryProvider()
on yourSimpleCursorAdapter
.