在蜂窝的装载机的API被引入适当的方式提供数据的应用程序通过执行繁重的后台线程。在我的应用我的工作,以取代我的所有光标
s的装载机
s表示返回光标
秒。由于 Cursor.requery()
现在pciated德$ P $,建议只需要调用 restartLoader
,并允许工作再次在后台线程完成,然后 changeCursor
,当它在 onLoadFinished
返回。
In Honeycomb the Loader APIs were introduced as the proper way to provide data to an application by doing the heavy lifting on a background thread. In my application I'm working to replace all my Cursor
s with Loader
s that return Cursor
s. Since Cursor.requery()
is depreciated now, it is recommended to just call restartLoader
and allow the work to again be done on a background thread and then changeCursor
when it returns in onLoadFinished
.
所有这些奇妙的作品不同的是ListView控件不保持它的滚动位置时,我想重新查询数据,使用 Cursor.requery()
这个曾经工作因为它是与更新的数据相同的光标实例。
All of this works wonderfully except that the ListView doesn't maintain it's scroll position when I want to requery the data, using Cursor.requery()
this used to work because it was the same Cursor instance with updated data.
我怎么能刷新我的装载机没有松动的滚动位置?
How can I refresh my Loader without loosing the scroll position?
在装载机
类本身不知道什么时候该数据集的变化,并具体落实到 CursorLoader
当前。现在,我的应用程序里面,我需要刷新数据是本地SQLite数据库(无ContentProvider的)里面,所以我不得不修改 CursorLoader
使用我的本地数据库,而不是作为戴安娜Hackborne在developer组。
The Loader
class by itself doesn't know when the dataset changes and is implementation specific to CursorLoader
currently. Now inside my application the data I needed to refresh is inside a local SQLite database (no ContentProvider) so I had to modify the CursorLoader
to use my local database instead, as Dianne Hackborne mentioned on the developer group.
不幸的是刚刚返回从loadInBackground游标不允许 ContentObserver
正确通知程序的时候,数据的变化,这是因为 AbstractCursor
只要求 notifyChanged()
在重新查询()
被称为上的光标。
Unfortunately just returning a Cursor from loadInBackground doesn't allow the ContentObserver
to properly notify the Loader when the data changes, this is because AbstractCursor
only calls notifyChanged()
when requery()
is called on the Cursor.
由于 ContentObserver
将永远不会通知装载机
的数据发生了变化,我最终调用 Loader.onContentChanged()
自己是必要的。在这一点上一切都似乎是工作,但如果有显著问题arrise我会更新这个答案。
Since the ContentObserver
will never notify the Loader
that the data has changed, I ended up calling Loader.onContentChanged()
myself as needed. At this point it everything seems to be working but I'll update this answer if any significant issues arrise.