关于使用LoaderManager异步加载数据库的一个问题

我没有在Activity或者Fragment中,而是在类里面继承LoaderManager.LoaderCallbacks

代码如下
public class SecCursorMenu implements LoaderManager.LoaderCallbacks {
private final int loadersong = 33, loadersinger = 34, loaderfavor = 35, loaderfilm = 36;
private SecCursorAdapter secCursorAdapter;
Context context;
private RecyclerView cmenuView;

public SecCursorMenu(RecyclerView cmenuView, Context context) {
    this.context = context;
    this.cmenuView = cmenuView;

}

public void init(RecyclerView cmenuView) {
    this.cmenuView = cmenuView;
    secCursorAdapter = new SecCursorAdapter(context, null, 0);
    if (this.cmenuView != null){

        this.cmenuView.setAdapter(secCursorAdapter);
    }

}

。。。。

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    int id = loader.getId();

    switch (id) {
        case loadersong:
            secCursorAdapter.swapCursor(data);
            break;
        case loaderfilm:
            secCursorAdapter.swapCursor(data);
            break;
        case loaderfavor:
            secCursorAdapter.swapCursor(data);
            break;
    }
}

@Override
public void onLoaderReset(Loader<Cursor> loader) {
    int id = loader.getId();

    switch (id) {
        case loadersong:
            secCursorAdapter.swapCursor(null);
            break;
        case loaderfilm:
            secCursorAdapter.swapCursor(null);
            break;
        case loaderfavor:
            secCursorAdapter.swapCursor(null);
            break;
    }
}

}


想context.getLoaderManager() 但是发现不行,求大神指点。。

1个回答

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐