Note that there are some explanatory texts on larger screens.

plurals
  1. POError on LoaderManager when using Support Library
    text
    copied!<p>I'm trying to convert my code from using cursors to using CursorLoaders. In order to support older versions of Android, I've installed the Support Library and instead of importing android.content.CursorLoader, I'm importing android.support.v4.content.CursorLoader. Now code that compiled fine is throwing two errors. The first error is on LoaderManager when I implement it. The error is: LoaderManager cannot be resolved to a type. The second error is on the call to initLoader. The error is: The method initLoader(int, Bundle, LoaderManager.LoaderCallbacks) in the type LoaderManager is not applicable for the arguments (int, Bundle, MyList). Here's my code:</p> <pre><code>public class MyList extends ListActivity implements LoaderManager.LoaderCallbacks&lt;Cursor&gt; { private static final String[] PROJECTION = new String[] { "_id", "fieldname" }; private static final int LOADER_ID = 0; private static final String MYTABLE_BASEPATH = "MyTable_tbl"; private static final String AUTHORITY = "SQLData"; public static final Uri MY_URI = Uri.parse("content://" + AUTHORITY + "/" + MYTABLE_BASEPATH); private SimpleCursorAdapter mAdapter; @SuppressWarnings("deprecation") @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent myData = getIntent(); Bundle info = myData.getExtras(); if (info != null){ Cursor c; String[] dataColumns = { "fieldname" }; int[] viewIDs = { R.id.mylist1 }; SimpleCursorAdapter adapter; adapter = new SimpleCursorAdapter(this, R.layout.mylist, null, dataColumns, viewIDs, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER); setListAdapter(adapter); getLoaderManager().initLoader(0, info, this); } } public Loader&lt;Cursor&gt; onCreateLoader(int id, Bundle args) { String selection = "level = '" + args.getString("Level") + "'"; return new CursorLoader(this, MY_URI, PROJECTION, selection, null, null); } public void onLoadFinished(Loader&lt;Cursor&gt; loader, Cursor cursor) { switch (loader.getId()) { case LOADER_ID: mAdapter.swapCursor(cursor); break; } } public void onLoaderReset(Loader&lt;Cursor&gt; loader) { mAdapter.swapCursor(null); } </code></pre> <p>}</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload