initLoader(INT,android.os.Bundle,android.support.v4.app.LoaderManager.LoaderCallbacks)全部错误' 不能是应用于'(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 {
//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);
}
}
2017-03-04
bous006