。getLoaderManager()initLoader()不接受'这个'作为参数虽然类(ListFragment)实现LoaderManager.LoaderCallbacks<光标> [英] getLoaderManager().initLoader() doesn't accept 'this' as argument though the class (ListFragment) implements LoaderManager.LoaderCallbacks<Cursor>

查看:162
本文介绍了。getLoaderManager()initLoader()不接受'这个'作为参数虽然类(ListFragment)实现LoaderManager.LoaderCallbacks<光标>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的在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;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆