问题描述
我有以下的在Android中使用SQLite一个指南麻烦。我使用的,而不是一个 ListFragment
A ListActivity
(如上例),所以我有 ListFragment
实施 LoaderManager.LoaderCallbacks<光标>
代替。然后,在 fillData()
方法 ListFragment
:
I'm having trouble following a guide on using SQLite in Android. I'm using a ListFragment
instead of a ListActivity
(as in the example), so I have the ListFragment
implement LoaderManager.LoaderCallbacks<Cursor>
instead. Then, in the fillData()
method in the ListFragment
:
private void fillData() {
// Fields from the database (projection)
// Must include the _id column for the adapter to work
String[] from = new String[] { NotesSQLiteHelper.COLUMN_TITLE };
// Fields on the UI to which we map
int[] to = new int[] { R.id.label };
getLoaderManager().initLoader(0, null, this); //error
adapter = new SimpleCursorAdapter(getApplicationContext(), R.layout.notes_row, null, from, to, 0);
setListAdapter(adapter);
}
我得到的错误:
I get the error:
The method initLoader(int, Bundle, LoaderManager.LoaderCallbacks<D>) in the type LoaderManager is not applicable for the arguments (int, null, NotesActivity.ArrayListFragment)
在标线,即使这
工具 LoaderManager.LoaderCallbacks&LT;光标&GT;
感谢你的任何想法。
推荐答案
您没有使用 CursorLoader
和装载机的正确实施
。删除旧的进口和使用这些的:
You are not using the right implementations of CursorLoader
and Loader
.Remove your old imports and use these ones:
import android.support.v4.app.LoaderManager;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.support.v4.widget.CursorAdapter;
但我用SherlockActionBar同样的问题:当我不得不延长 SherlockListActivity
有没有方法 getSupportLoadManager()
。
But I have the same Problem using SherlockActionBar:As I have to extend SherlockListActivity
there is NO method getSupportLoadManager()
.
对此有何想法?
编辑:遵循的,如果你不知道如何使用的片段。创建一个新的类与扩展SherlockFragment和移动你的显示逻辑存在。让你的老年活动延长SherlockFragmentActivity并显示新创建的SherlockFragment。这样,我得到它的工作。由于@JakeWharton!
follow this tutorial if you do not know how to use fragments. Create a new Class with extends SherlockFragment and move your display logic there. Make your old activity extend SherlockFragmentActivity and show the newly created SherlockFragment. This way I got it working. Thanks to @JakeWharton!
这篇关于。getLoaderManager()initLoader()不接受'这个'作为参数虽然类(ListFragment)实现LoaderManager.LoaderCallbacks&LT;光标&GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!