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

后端 未结 19 1631
无人共我
无人共我 2020-12-07 16:19

I\'m having trouble following a guide on using SQLite in Android. I\'m using a ListFragment instead of a ListActivity(as in the example), so I have

19条回答
  •  借酒劲吻你
    2020-12-07 17:03

    I'm using ActionBarSherlock with my app and I as well was running into this issue and worked through all the steps discussed by others in this question. However I was continuing to have the same problem after trying all the suggested resolutions.

    The method initLoader(int, Bundle, LoaderManager.LoaderCallbacks) in the type LoaderManager is not applicable for the arguments (int, null, this)
    

    The issue was I had fallen into expecting Eclipse to tell me when I was missing something and it was telling me that but not in the way I was used to. Typically Eclipse in other cases would tell me I'm missing the overrides to make something work but it's not directly saying that here. I finally picked up on the "LoaderManager.LoaderCallbacks" being the issue and realized I had no callbacks for it thus this error was actually a very valid error. Adding the basic overrides resolved my issue and allowed me to move forward.

    // Creates a new loader after the initLoader () call
    @Override
    public Loader onCreateLoader(int id, Bundle args) {
      // do work
      return null;
    }
    
    @Override
    public void onLoadFinished(Loader loader, Cursor data) {
      adapter.swapCursor(data);
    }
    
    @Override
    public void onLoaderReset(Loader loader) {
      // data is not available anymore, delete reference
      adapter.swapCursor(null);
    }
    

提交回复
热议问题