文章结束给大家来个程序员笑话:[M]
returns its query results to your implementation of
, in the form of a
. In the callback, you can update your data display, do further processing on the
data, and so forth. http://blog.csdn.net/sergeycao
When the loader framework detects changes to data associated with the query, it resets the, closes the current
, and then invokes your implementation of
. Use this callback to delete references to the current
; when the loader framework destroys the
, you won't have outstanding references that cause memory leaks.
Handle Query Results
The following two snippets are an example of displaying the results of a query, using a backed by a
.
The first snippet shows the and
:
// Gets a handle to the Android built-in ListView widgetmListView = ((ListView) findViewById(android.R.id.list));// Creates a CursorAdaptermAdapter = new SimpleCursorAdapter( this, // Current context R.layout.logitem, // View for each item in the list null, // Don't provide the cursor yet FROM_COLUMNS, // List of cursor columns to display TO_FIELDS, // List of TextViews in each line 0 // flags);// Links the adapter to the ListViewmListView.setAdapter(mAdapter);
The next snippet shows an implementation of that moves the query results in the returned
to the
. Changing the
in the
triggers a refresh of the
with the new data:
public void onLoadFinished(Loaderloader, Cursor cursor){ /* * Move the results into the adapter. This * triggers the ListView to re-display. */ mAdapter.swapCursor(cursor);}
Handle a Loader Reset
The loader framework resets the whenever the
becomes invalid. This usually occurs because the data associated with the
has changed. Before re-running the query, the framework calls your implementation of
. In this callback, make sure to prevent memory leaks by deleting all references to the current
. Once you return from
, the loader framework re-runs the query.
For example:
public void onLoaderReset(Loaderloader){ // Remove the reference to the current Cursor mAdapter.swapCursor(null);}
文章结束给大家分享下程序员的一些笑话语录: 程序语言综述
CLIPPER 程序员不去真的猎捕大象,他们只是购买大象部分的库然后花几年的时间试图综合它们。 DBASE 程序员只在夜间猎捕大象,因为那时没人会注意到他们还在使用石弓。 FOXPRO 程序员开始使用更新更好的步枪,这使他们花掉比实际狩猎更多的时间学习新的射击技术。 C 程序员拒绝直接购买步枪,宁可带着钢管和一个移动式机器车间到非洲,意欲从零开始造一枝完美的步枪。 PARADOX 程序员去非洲时带着好莱坞关于猎捕大象的电影剧本,他们认为照剧本行事就会逮到一头大象。 ACCESS 程序员在没有任何猎象经验的经验下就出发了,他们穿着华丽的猎装、带着全部装备,用漂亮的望远镜找到了大象,然后发觉忘了带扳机。 RBASE 程序员比大象还要稀少,事实上,如果一头大象看到了一个RBASE程序员,对他是个幸运日。 VISUAL ACCESS 程序员装上子弹、举起步枪、瞄准大象,这使大象感到可笑,究竟谁逃跑。他们无法抓住大象,因为由于他们对多重控制的偏爱,他们的吉普车有太多的方向盘因而无法驾驶。 ADA、APL和FORTRAN 程序员与圣诞老人和仙女一样是虚构的。 COBOL 程序员对和自己一样濒临灭绝的大象寄予了深切的同情。