【发布时间】:2014-07-13 10:28:05
【问题描述】:
为什么我不能在 Fragment 项目中调用 SimpleCursorAdapter,这是我的代码:
private void fillData() {
Cursor notesCursor = mDbHelper.fetchAllNotes();
getActivity().startManagingCursor(notesCursor);
String[] from = new String[] { NotesDbAdapter.KEY_TITLE ,NotesDbAdapter.KEY_DATE};
int[] to = new int[] { R.id.text1 ,R.id.date_row};
SimpleCursorAdapter notes =
new SimpleCursorAdapter(this, R.layout.note_row, notesCursor, from, to);
setListAdapter(notes);
}
谢谢,请帮帮我,因为我正在赶截止日期
【问题讨论】:
-
错误是什么?首先想到的是您需要将
this替换为getActivity()。片段本身不是有效的上下文,上下文由底层 Activity 提供。 -
@cYrixmorten Yeees 它的工作,但我再次遇到 setListAdapter 错误,错误是“方法 setListAdapter(SimpleCursorAdapter) 未定义为 ReviewFragment 类型”我该怎么办?谢谢之前
-
嗯,从少量代码中很难分辨,但听起来你是在扩展
Fragment,但实际上是在扩展ListFragment
标签: android android-fragments fragment android-fragmentactivity simplecursoradapter