我整天都在为此工作,并一直试图了解它们是如何组合在一起的,并重新编写我的代码以使其很好地组合在一起。
所以我会告诉你我有什么。没有错误,只是空白。
MyAgendaLoaderManager.java:
public class MyAgendaLoaderManager implements LoaderCallbacks<Cursor>{
MyAgendaAdapter agendaAdapter;
Context mContext;
String date;
public MyAgendaLoaderManager(Context context, MyAgendaAdapter adapter, String date) {
agendaAdapter = adapter;
mContext = context;
this.date = date;
}
@Override
public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
Uri baseUri = SmartCalProvider.CONTENT_URI;
return new CursorLoader(mContext, baseUri,
new String[] {"_id, event_name, start_date, start_time, end_date, end_time, location"},
"WHERE date(?) >= start_date and date(?) <= end_date", new String[]{date, date}, null);
}
@Override
public void onLoadFinished(Loader<Cursor> arg0, Cursor arg1) {
// TODO Auto-generated method stub
agendaAdapter.swapCursor(arg1);
}
@Override
public void onLoaderReset(Loader<Cursor> arg0) {
// TODO Auto-generated method stub
agendaAdapter.swapCursor(null);
}
}
CalProvider.java:
public class SmartCalProvider extends ContentProvider {
public static final String AUTHORITY = "content://com.smartcal.eventprovider";
public static final Uri CONTENT_URI = Uri.parse(AUTHORITY);
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_NAME = "cal.db";
private SmartCalOpenHelper openHelper;
private SQLiteDatabase database;
@Override
public boolean onCreate() {
openHelper = new SmartCalOpenHelper(getContext());
return true;
}
@Override
public String getType(Uri uri) {
return null;
}
@Override
public Cursor query(Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder) {
database = openHelper.getWritableDatabase();
return database.query("events_info", projection, selection, selectionArgs, null, null, null);
}
@Override
public Uri insert(Uri uri, ContentValues values) {
return null;
}
@Override
public int delete(Uri arg0, String arg1, String[] arg2) {
return 0;
}
@Override
public int update(Uri uri, ContentValues values, String selection,
String[] selectionArgs) {
return 0;
}
}
如果它很重要,下面是在主要活动中运行它的代码:
agendaAdapter = new MyAgendaAdapter(this, null);
MyAgendaLoaderManager loader = new MyAgendaLoaderManager(this, agendaAdapter, getChosenDate());
我只是不明白它是如何空白的。请记住,我故意在 CursorLoader 和 LoaderManager 中留了一些空白,因为我不想全部填写以发现有错误,所以我只是在测试是否显示初始列表,并且它不是。任何帮助找出我做错了什么将不胜感激。
编辑:实际上,现在我考虑了一下,除了当我的适配器创建包含它的视图时,没有什么能真正将我正在做的事情与特定列表联系起来。但该视图不是常规布局的一部分。所以也许这就是我的错误,不幸的是我不知道该怎么做。