nullnullHandling the Results 处理结果

文章结束给大家来个程序员笑话:[M]

    CursorLoader returns its query results to your implementation ofLoaderCallbacks.onLoadFinished(), in the form of a Cursor. In the callback, you can update your data display, do further processing on theCursor data, and so forth. http://blog.csdn.net/sergeycao

    When the loader framework detects changes to data associated with the query, it resets theCursorLoader, closes the current Cursor, and then invokes your implementation ofonLoaderReset(). Use this callback to delete references to the currentCursor; when the loader framework destroys the Cursor, 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 aListView backed by a SimpleCursorAdapter.

    The first snippet shows the ListView and SimpleCursorAdapter:

// Gets a handle to the Android built-in ListView widget
mListView = ((ListView) findViewById(android.R.id.list));
// Creates a CursorAdapter
mAdapter =
    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 ListView
mListView.setAdapter(mAdapter);
    每日一道理
谁说人与人隔着遥远的重洋,谁说心与心设着坚固的堤防?十六岁的鸟儿飞上天空,总会找到落脚的枝头。

    The next snippet shows an implementation of onLoadFinished() that moves the query results in the returnedCursor to the SimpleCursorAdapter. Changing theCursor in the SimpleCursorAdapter triggers a refresh of theListView with the new data:

public void onLoadFinished(Loader<Cursor> loader, 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 CursorLoader whenever theCursor becomes invalid. This usually occurs because the data associated with theCursor has changed. Before re-running the query, the framework calls your implementation ofonLoaderReset(). In this callback, make sure to prevent memory leaks by deleting all references to the currentCursor. Once you return from onLoaderReset(), the loader framework re-runs the query.

    For example:

public void onLoaderReset(Loader<Cursor> loader)
{
    // Remove the reference to the current Cursor
    mAdapter.swapCursor(null);
}

文章结束给大家分享下程序员的一些笑话语录: 程序语言综述
CLIPPER 程序员不去真的猎捕大象,他们只是购买大象部分的库然后花几年的时间试图综合它们。
DBASE 程序员只在夜间猎捕大象,因为那时没人会注意到他们还在使用石弓。
FOXPRO 程序员开始使用更新更好的步枪,这使他们花掉比实际狩猎更多的时间学习新的射击技术。
C 程序员拒绝直接购买步枪,宁可带着钢管和一个移动式机器车间到非洲,意欲从零开始造一枝完美的步枪。
PARADOX 程序员去非洲时带着好莱坞关于猎捕大象的电影剧本,他们认为照剧本行事就会逮到一头大象。
ACCESS 程序员在没有任何猎象经验的经验下就出发了,他们穿着华丽的猎装、带着全部装备,用漂亮的望远镜找到了大象,然后发觉忘了带扳机。
RBASE 程序员比大象还要稀少,事实上,如果一头大象看到了一个RBASE程序员,对他是个幸运日。
VISUAL ACCESS 程序员装上子弹、举起步枪、瞄准大象,这使大象感到可笑,究竟谁逃跑。他们无法抓住大象,因为由于他们对多重控制的偏爱,他们的吉普车有太多的方向盘因而无法驾驶。
ADA、APL和FORTRAN 程序员与圣诞老人和仙女一样是虚构的。
COBOL 程序员对和自己一样濒临灭绝的大象寄予了深切的同情。

posted @ 2013-05-09 20:34  坚固66  阅读(241)  评论(0编辑  收藏  举报