在安卓系统中使用SQLite时,我在guide上遇到了问题。我使用的是ListFragment而不是ListActivity(如示例所示),因此我让ListFragment实现LoaderManager.LoaderCallbacks<Cursor>。然后,在ListFragment中的fillData()方法中
private void fillData() {
// Fields from the database (projection)
// Must include the _id column for the adapter to work
String[] from = new String[] { NotesSQLiteHelper.COLUMN_TITLE };
// Fields on the UI to which we map
int[] to = new int[] { R.id.label };
getLoaderManager().initLoader(0, null, this); //error
adapter = new SimpleCursorAdapter(getApplicationContext(), R.layout.notes_row, null, from, to, 0);
setListAdapter(adapter);
}我得到了错误:
The method initLoader(int, Bundle, LoaderManager.LoaderCallbacks<D>) in the type LoaderManager is not applicable for the arguments (int, null, NotesActivity.ArrayListFragment)在标记的行上,即使this实现了LoaderManager.LoaderCallbacks<Cursor>。
谢谢你的任何想法。
发布于 2020-04-18 00:22:43
如果您使用API28或更高版本,而不是getLoaderManager,请使用:
getSupportLoaderManager().initLoader(id, null, this);https://stackoverflow.com/questions/11155753
复制相似问题