Notice how MyCursor is initialized with a MatrixCursor in the beginning (see Listing 13-18). On requery, MyCursor will call back the provider to return a MatrixCursor. Then the new MatrixCursor will replace the old one by using the set method.

We could have done this by overriding the requery of the MatrixCursor, but that class does not provide a way to clear the data and start all over again. So this is a reasonable workaround. (Note that MyCursor extends BetterCursorWrapper; we'll discuss the latter in the next subsection.)

Listing 13-18. MyCursor Source Code public class MyCursor extends BetterCursorWrapper {

private ContentProvider mcp = null;

public MyCursor(MatrixCursor mc, ContentProvider inCp) {

public boolean requery() {

MatrixCursor mc = MyContactsProvider.loadNewData(mcp);


return super.requery();

Now you'll look at the BetterCursorWrapper class to get an idea of how to wrap a cursor.

0 0

Post a comment