How can I reference a cursor

53 views Asked by At

I wish to use a CursorLoader in my application but I don't want to use the returned cursor with a SimpleCursorAdapter. I just want to get a reference of the cursor returned from onLoadFinished()

Here is some code

 public class MainActivity extends Activity implements LoaderManager.LoaderCallbacks<Cursor>

    {

    @Override

    public void onCreate(Bundle arg)

    {

    getLoaderManager().initLoader(0, null, this);

    }


 @Override


public Loader<Cursor> onCreateLoader(int id, Bundle args) 

      {

      return new CursorLoader(getActivity(), baseUri,PROJECTION, select, null, COLNAME );


   }

 @Override

public void onLoadFinished(Loader<Cursor> loader, Cursor data) 

    {
    // rather than swap the cursor with SimpleCursorAdapter reference, I wish to return the cursor so I can reference it


     }

    }

Any ideas how this can be done

1

There are 1 answers

0
ILovemyPoncho On BEST ANSWER

You could just create class member:

private Cursor mCursor;

...

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    mCursor = data;
}

@Override
public void onLoaderReset(Loader<Cursor> loader) {
    mCursor = null;
}

from de docs: onLoaderReset - Called when a previously created loader is being reset, and thus making its data unavailable. The application should at this point remove any references it has to the Loader's data.

And HERE you can see ways to iterate a cursor.