问题
I want to filter out some rows returned by a Cursor based on a specific condition (which I want to test after receiving the rows from the database, because it's not easy to add it to a WHERE clause in the SQL query). I found the following related questions: Filter rows from Cursor so they don't show up in ListView, Filtering a cursor the right way?, and How to hide specific rows of a Cursor in android. I want to implement exactly what those questions are asking.
While the answers to those questions show how to implement a CursorWrapper (which I have done), I don't know how to then link that CursorWrapper to the Cursor & CursorAdapter. The answers just say "Then, use your CursorWrapper in the SimpleCursorAdapter" - can someone elaborate on what this means? Specifically, where do you instantiate the CursorWrapper class and how do you use it in conjunction with the CursorAdapter?
Thanks.
回答1:
CursorWrapper
implements the Cursor
interface, so you can pass your CursorWrapper
to your CursorAdapter
in place of your Cursor
.
来源:https://stackoverflow.com/questions/17333490/how-to-use-cursorwrapper-to-filter-cursor-rows