getLoaderManager().initLoader() doesn't accept 'this' as argument though the class (ListFragment) implements LoaderManager.LoaderCallbacks<Cursor> getLoaderManager().initLoader() doesn't accept 'this' as argument though the class (ListFragment) implements LoaderManager.LoaderCallbacks<Cursor> android android

getLoaderManager().initLoader() doesn't accept 'this' as argument though the class (ListFragment) implements LoaderManager.LoaderCallbacks<Cursor>


You are not using the right implementations of CursorLoader and Loader.Remove your old imports and use these ones:

import android.support.v4.app.LoaderManager;import android.support.v4.content.CursorLoader;import android.support.v4.content.Loader;import android.support.v4.widget.CursorAdapter;

But I have the same Problem using SherlockActionBar:As I have to extend SherlockListActivity there is NO method getSupportLoadManager().

Any ideas on this?

EDIT: follow this tutorial if you do not know how to use fragments. Create a new Class with extends SherlockFragment and move your display logic there. Make your old activity extend SherlockFragmentActivity and show the newly created SherlockFragment. This way I got it working. Thanks to @JakeWharton!


A few things to watch out for (from my recent experience battling with this):

  1. If your minSDK is set to less than 11 (i.e. level 10 for Gingerbread) and you are using the Support Pack for backward compatibility, make sure you use

    getSupportLoaderManager().initLoader(LOADER_ID, null, this);
  2. You mentioned this when you said you are using ListFragment, but it bears repeating: Do not extend Activity, otherwise the support package will not work. Instead, extend the FragmentActivity class or the ListFragment class.

  3. For your imports, make sure you are using the correct versions if your minSDK < 11:

     android.support.v4.app.FragmentActivity; android.support.v4.app.LoaderManager; android.support.v4.content.Loader;

Hope this helps you... or at least someone else...


Casting the third argument solved the problem in my case:

from

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

to

 getLoaderManager().initLoader(0, null, (android.app.LoaderManager.LoaderCallbacks<Cursor>) this);

Note:

  1. minSdk was 8 and i was using support library v4.
  2. (android.support.v4.app.LoaderManager.LoaderCallbacks<Cursor>) this)did not work.
  3. getSupportLoaderManager() or getSupportLoadManager()did not work.
  4. This code was inside activity not fragment