I'm using an activity and a fragment based on ActionBarSherlock. To read rows from an SQLite database I'm trying to use a Loader
instead of a ContentProvider
, and I'm trying to get LoaderEx to work for me.
I'm stuck with a stubborn problem: in my fragment's onCreateLoader
callback, ADT is consistently giving me an error:
"Cannot convert from SQLiteCursorLoader to Loader<Cursor>"
I'm using the Android v4 Support Library. Because of DEX errors, I've removed android-support-v4.jar
from both ActionBarSherlock and LoaderEx, and added it into my base project instead. Then I've made both ABS and LoaderEx depend on that.
ABS and LoaderEx are both added as a library project.
I've checked that I'm only using the v4 imports. Also LoaderExDemo compiles and works in an emulator.
These are my fragment's imports:
import com.actionbarsherlock.app.SherlockListFragment;
import android.database.Cursor;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ListView;
import android.support.v4.widget.SimpleCursorAdapter;
import android.support.v4.app.LoaderManager;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import com.commonsware.cwac.loaderex.SQLiteCursorLoader;
Here's my fragment declaration:
public class MeetingListFragment
extends SherlockListFragment
implements LoaderManager.LoaderCallbacks<Cursor> {
private JournalDatabaseHelper db = null;
private SimpleCursorAdapter adapter = null;
private SQLiteCursorLoader loader = null;
And here's the getLoader
callback method:
public Loader<Cursor> onCreateLoader(int loaderId, Bundle args) {
loader = new SQLiteCursorLoader(getSherlockActivity().getApplicationContext(),
db,
"SELECT _ID, meeting_timestamp, meeting_desc FROM meeting " +
"ORDER BY meeting_timestamp DESC",
null);
return loader; // <<< this is the line of the ADT/Eclipse error
}
I've gone back and forth with this for hours. Some answers on SO are kind of in the area, but no real solutions. What is going wrong?
You have:
import com.commonsware.cwac.loaderex.SQLiteCursorLoader;
That is the wrong SQLiteCursorLoader
, as that is the one for the native API Level 11+ version of the Loader
framework. As noted in the LoaderEx documentation, you should be using com.commonsware.cwac.loaderex.acl.SQLiteCursorLoader
if you are using the Loader
backport from the Android Support package.