getSupportLoaderManager()中的第三个参数.initLoader()

时间:2018-02-23 17:51:58

标签: android android-loadermanager

嗨,我是新来的,也是android的初学者,我正在制作一个名为“contactsLoader”的LoadManager,并在游标中进行回调

private LoaderManager.LoaderCallbacks<Cursor> contactsLoader =
        new LoaderManager.LoaderCallbacks<Cursor>() {
    @Override
    public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
        String[] projectionFields = new String[]{
                ContactsContract.Contacts._ID,
                ContactsContract.Contacts.DISPLAY_NAME,
                ContactsContract.Contacts.PHOTO_URI
        };

        CursorLoader cursorLoader = new CursorLoader(MainActivity.this,
                ContactsContract.Contacts.CONTENT_URI,
                projectionFields,
                null,
                null,
                null);
        return cursorLoader;
    }

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

        adapter.swapCursor(data);
    }

    @Override
    public void onLoaderReset(Loader<Cursor> loader) {
        adapter.swapCursor(null);
    }
};

问题是我每次调用函数getSupportLoaderManager()。initLoader()

private void loadingContacts() {
    Log.d(DEBUG,"We have permission to load the contacts");
    getSupportLoaderManager().initLoader(CONTACT_LOADER_ID,new Bundle(),contactsLoader);
}

出现此错误:

Wrong 3rd argument "contactsLoader". Found: 'android.app.LoaderManager.LoaderCallbacks<android.database.Cursor>', required: 'android.support.v4.app.LoaderManager.LoaderCallbacks<java.lang.Object>'

我试图通过这些链接了解问题是什么LoaderManagerLoaders,但我找不到解决方案

0 个答案:

没有答案