Better CursorWrapperjava

The BetterCursorWrapper class (see Listing 13-19) is very similar to the CursorWrapper class in the Android database framework. But we need two additional things that CursorWrapper lacks. First, it doesn't have a set method to replace the internal cursor from the requery method. Second, CursorWrapper is not a CrossProcessCursor. Live folders need a CrossProcessCursor as opposed to a plain cursor because live folders work across process boundaries.

Listing 13-19. BetterCursorWrapper Source Code public class BetterCursorWrapper implements CrossProcessCursor {

//Holds the internal cursor to delegate methods to protected CrossProcessCursor internalCursor;

//Constructor takes a crossprocesscursor as an input public BetterCursorWrapper(CrossProcessCursor inCursor) {

this.setlnternalCursor(inCursor);

//You can reset in one of the derived class's methods public void setInternalCursor(CrossProcessCursor inCursor) {

internalCursor = inCursor; //All delegated methods follow public void fillWindow(int arg0, CursorWindow argl) { internalCursor.fillWindow(arg0, argl);

// other delegated methods

We haven't shown you the entire class, but you can easily use Eclipse to generate the rest of it. Once you have this partial class loaded into Eclipse, place your cursor on the variable named internalCursor. Right-click and choose Source > Generate Delegated Methods. Eclipse will then populate the rest of the class for you. Let us now show you the simple activity you need to complete this sample project.

0 0

Post a comment