使用装载机用游标 [英] Using Loaders with Cursors
问题描述
我想用 CursorLoaders
来从数据库中加载的日期,但问题是我不想处理的CursorAdapter或者decants我想有光标
,因为它是。
I want to use CursorLoaders
to load date from database but the problem is i dont want to handle a CursorAdapter or it decants i want to have the Cursor
as it is .
下面是我做的。
class MyClass implements LoaderCallbacks<Cursor> {
Cursor mCursor;
...
...
...
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle bundle) {
if (type == V_TYPE_PART) {
// load all parts
return new CursorLoader(getActivity(),
PartTableMetaData.CONTENT_URI,
PartTableMetaData.TABLE_COLUMNS, null, null,
PartTableMetaData._ID + " ASC");
}
return null;
}
@Override
public void onLoadFinished(Loader<Cursor> arg0, Cursor arg1) {
counterPartCursor = arg1;
//update the UI
}
@Override
public void onLoaderReset(Loader<Cursor> arg0) {
mCursor= null;
}
}
现在这项工作很好。我的问题是我在做正确的方式?或者我应该做别的东西像关闭游标在 onLoaderReset
??
Now this work fine . My Question is i am doing it the right way ? or should i make something else like closing the cursor in the onLoaderReset
??
推荐答案
没有关闭游标不required.setting空会使事情工作作为CursorLoader将其关闭的照顾。但我可以看到在当前code泄漏为
No closing the cursor is not required.setting null will make the things work as CursorLoader will take care of closing it. But I can see the leakage in your current code as
@Override
public void onLoadFinished(Loader<Cursor> arg0, Cursor arg1) {
counterPartCursor = arg1;
//update the UI
}
@Override
public void onLoaderReset(Loader<Cursor> arg0) {
mCursor= null;
}
您持有的counterPartCursor参考,使mCursor空!
you are holding reference in counterPartCursor and making mCursor null !!!
这篇关于使用装载机用游标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!