0

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

Psypher
  • 10,717
  • 12
  • 59
  • 83
Michael Okoli
  • 4,887
  • 2
  • 16
  • 20
  • 1
    you can save a reference if you want, and iterate through it to use its data, it's not necessary to use a cursoradapter, what is the problem you have? – ILovemyPoncho Jun 17 '15 at 18:37
  • @ILovemyPoncho If u can please, help me with the codes of how to save the reference of the cursor – Michael Okoli Jun 17 '15 at 18:47

1 Answers1

2

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.

Community
  • 1
  • 1
ILovemyPoncho
  • 2,762
  • 2
  • 24
  • 37