问题描述
要我现在还不清楚如何得到正确的光标,如果你有多个装载机。比方说,你定义了两种不同的加载器:
To me it's not clear how to get the right cursor if you have multiple Loaders. Lets say you define two different Loader with:
getLoaderManager().initLoader(0,null,this);
getLoaderManager().initLoader(1,null,this);
然后在 onCreateLoader()你根据ID不同的事情:
then in onCreateLoader() you do different things depending on the id:
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle arg1) {
if (id==0){
CursorLoader loader = new CursorLoader(getActivity(),
MaterialContentProvider.CONTENT_URI,null,null,null,null);
}else{
CursorLoader loader = new CursorLoader(getActivity(),
CustomerContentProvider.CONTENT_URI,null,null,null,null);
};
return loader;
}
到目前为止好。但如何得到正确的光标 onLoadFinished(),因为你没有得到任何的ID,以确定正确的光标合适的CursorAdapter。
so far so good. But how to get the right cursor in onLoadFinished() because you don't get any id to identify the right Cursor for the right Cursoradapter.
@Override
public void onLoadFinished(Loader<Cursor> arg0, Cursor cursor) {
mycursoradapter1.swapCursor(cursor);
if(isResumed()){
setListShown(true);
}else {
setListShownNoAnimation(true);
}
}
//and where to get the cursor for mycursoradapter2
还是我错了,这是错误的方式来获得一个片段,结果两个不同的CursorAdapter。
or am I wrong and this is the wrong way to get results for two different cursoradapter in one fragment.
推荐答案
Loader类有一个名为的。我希望这将返回你的加载器相关的标识。
The Loader class has a method called getId(). I would hope this returns the id you've associated with the loader.
这篇关于LoaderManager多个装载机:如何得到正确的cursorloader的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!