initLoader 调用未将 "this" 作为第三个参数。完整错误如下

initLoader call not taking "this" as third argument. Full error below

错误

initLoader(int, android.os.Bundle, android.support.v4.app.LoaderManager.LoaderCallbacks)' in 'android.support.v4.app.LoaderManager' cannot be applied to '(int, null, group15.cop4331project.MyReportsFragment)

我已经阅读了有关支持库的所有答案,但事实并非如此。我正在尝试使用 SQLite 数据库中的列表填充此片段。我真的很想弄清楚为什么这不起作用。另外,我认为我正确使用了 OnCreateView 和 OnActivityCreated,但我不确定。

我的导入

import android.content.ContentUris;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

我的代码

public class MyFragment extends Fragment implements LoaderManager.LoaderCallbacks < Cursor > {

    //adapter for the ListView
    MyCursorAdapter mCursorAdapter;

    View rootView;

    public MyReportsFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        rootView = inflater.inflate(R.layout.report_list, container, false);

        return rootView;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        // Find the listview which will be populated with the data
        ListView listView = (ListView) rootView.findViewById(R.id.list);

        // Setup an Adapter to create a list item for each row of  data in the Cursor.
        mCursorAdapter = new ReportCursorAdapter(getActivity(), null);
        listView.setAdapter(mCursorAdapter);

        // Setup the item click listener
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {@Override
            public void onItemClick(AdapterView < ?>adapterView, View view, int position, long id) {
                Intent intent = new Intent(getActivity(), EditReportActivity.class);

                Uri currentUri = ContentUris.withAppendedId(ReportEntry.CONTENT_URI, id);

                // Set the URI on the data field of the intent
                intent.setData(currentUri);

                startActivity(intent);
            }
        });

        // Kick off the loader
        getLoaderManager().initLoader(REPORT_LOADER, null, this);
        //getActivity().getSupportLoaderManager().initLoader(REPORT_LOADER, null, this);
    }
}

应该在 onActivityCreated 中调用 initLoader 才可以。

我遇到了类似的问题,解决方案与支持 v4 库有关。更改此导入语句: import android.support.v4.app.Fragment; 到: import android.app.Fragment; 并使用:import android.app.LoaderManager; (确保您没有在项目的任何地方使用 v4 支持)

这是基于您 post 编写的代码,如果您可以 post 所有可能有用的 imort 语句

希望这对您有所帮助