问题描述
我正在尝试在我的应用程序上实现内容提供程序。
预期行为:在 createLoaderCourses() 方法的末尾,返回一个 CursorLoader 应该会引导我到内容提供程序上名为“查询”的方法。
实际行为: createLoaderCourses() 方法直接返回空值,没有调用内容提供者的“查询”方法。
下面是返回 null 而不是 CursorLoader 的方法。
private CursorLoader createLoaderCourses() {
mCoursesQueryFinished = false;
Uri uri = Uri.parse("content://com.example.notekeeper.provider");
String[] courseColumns = {
CourseInfoEntry.COLUMN_COURSE_TITLE,CourseInfoEntry.COLUMN_COURSE_ID,CourseInfoEntry._ID
};
return new CursorLoader(this,uri,courseColumns,null,CourseInfoEntry.COLUMN_COURSE_TITLE);
}
这是我的提供者类:
package com.example.notekeeper;
import android.content.ContentProvider;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import com.example.notekeeper.NoteKeeperDatabaseContract.CourseInfoEntry;
public class NoteKeeperProvider extends ContentProvider {
private NoteKeeperOpenHelper mDbOpenHelper;
public NoteKeeperProvider() {
}
@Override
public int delete(Uri uri,String selection,String[] selectionArgs) {
// Implement this to handle requests to delete one or more rows.
throw new UnsupportedOperationException("Not yet implemented");
}
@Override
public String getType(Uri uri) {
// TODO: Implement this to handle requests for the MIME type of the data
// at the given URI.
throw new UnsupportedOperationException("Not yet implemented");
}
@Override
public Uri insert(Uri uri,ContentValues values) {
// TODO: Implement this to handle requests to insert a new row.
throw new UnsupportedOperationException("Not yet implemented");
}
@Override
public boolean onCreate() {
mDbOpenHelper = new NoteKeeperOpenHelper(getContext());
return true;
}
/**
*
* @param uri
* @param projection Columns that we want to select
* @param selection
* @param selectionArgs
* @param sortOrder
* @return
*/
@Override
public Cursor query(Uri uri,String[] projection,String[] selectionArgs,String sortOrder) {
SQLiteDatabase db = mDbOpenHelper.getReadableDatabase();
Cursor cursor = db.query(CourseInfoEntry.TABLE_NAME,projection,selection,selectionArgs,sortOrder);
return cursor;
}
@Override
public int update(Uri uri,ContentValues values,String[] selectionArgs) {
// TODO: Implement this to handle requests to update one or more rows.
throw new UnsupportedOperationException("Not yet implemented");
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)