博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Handling the Results 处理结果
阅读量:4045 次
发布时间:2019-05-24

本文共 2141 字,大约阅读时间需要 7 分钟。

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(Loader
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 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(Loader
loader){ // Remove the reference to the current Cursor mAdapter.swapCursor(null);}
你可能感兴趣的文章
WebSocket(2)--为什么引入WebSocket协议
查看>>
WebSocket(3)-- WebSocket协议简介
查看>>
WebSocket(4)-- WebSocket与TCP、Http的关系
查看>>
TCP/IP, WebSocket 和 MQTT
查看>>
CentOS、Ubuntu、Debian三个linux比较异同
查看>>
javascript闭包和闭包的几种写法及用途
查看>>
Js作用域与作用域链详解
查看>>
nginx下 499错误
查看>>
网络性能测试工具iperf详细使用图文教程
查看>>
MacOSX上ab并发测试常见报错及解决办法
查看>>
为你的网站开启 gzip 压缩功能(nodejs、nginx)
查看>>
网页性能管理详解
查看>>
try catch 对代码运行的性能影响
查看>>
Koa框架实践与中间件原理剖析
查看>>
node.js 资料收集
查看>>
解除 Linux 系统的最大进程数和最大文件打开数限制
查看>>
怎样才是一个基本水平的java程序员?
查看>>
UGC,PGC,OGC
查看>>
一道关于Promise应用的面试题
查看>>
Couchbase 介绍 - 更好的 Cache 系统
查看>>