Loading Data in the Background 之Handling the Results
来源:互联网 发布:无主之地2mac下载 编辑:程序博客网 时间:2024/05/13 21:14
为了显示cursor的数据,一般会用view + adapterView的方式。然后在onLoadFinished()方法中更新adapter
如下所示:
public String[] mFromColumns = {
DataProviderContract.IMAGE_PICTURENAME_COLUMN
};
public int[] mToFields = {
R.id.PictureName
};
// Gets a handle to a List View
ListView mListView = (ListView) findViewById(R.id.dataList);
/*
* Defines a SimpleCursorAdapter for the ListView
*
*/
SimpleCursorAdapter mAdapter =
new SimpleCursorAdapter(
this, // Current context
R.layout.list_item, // Layout for a single row
null, // No Cursor yet
mFromColumns, // Cursor columns to use
mToFields, // Layout fields to use
0 // No flags
);
// Sets the adapter for the view
mListView.setAdapter(mAdapter);
...
/*
* Defines the callback that CursorLoader calls
* when it's finished its query
*/
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
...
/*
* Moves the query results into the adapter, causing the
* ListView fronting this adapter to re-display
*/
mAdapter.changeCursor(cursor);
}
Delete Old Cur
public String[] mFromColumns = {
DataProviderContract.IMAGE_PICTURENAME_COLUMN
};
public int[] mToFields = {
R.id.PictureName
};
// Gets a handle to a List View
ListView mListView = (ListView) findViewById(R.id.dataList);
/*
* Defines a SimpleCursorAdapter for the ListView
*
*/
SimpleCursorAdapter mAdapter =
new SimpleCursorAdapter(
this, // Current context
R.layout.list_item, // Layout for a single row
null, // No Cursor yet
mFromColumns, // Cursor columns to use
mToFields, // Layout fields to use
0 // No flags
);
// Sets the adapter for the view
mListView.setAdapter(mAdapter);
...
/*
* Defines the callback that CursorLoader calls
* when it's finished its query
*/
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
...
/*
* Moves the query results into the adapter, causing the
* ListView fronting this adapter to re-display
*/
mAdapter.changeCursor(cursor);
}
通过实现onLoaderReset方法删除旧的数据
public void onLoaderReset(Loader<Cursor> loader) {
/*
* Clears out the adapter's reference to the Cursor.
* This prevents memory leaks.
*/
mAdapter.changeCursor(null);
}
如下所示:
public String[] mFromColumns = {
DataProviderContract.IMAGE_PICTURENAME_COLUMN
};
public int[] mToFields = {
R.id.PictureName
};
// Gets a handle to a List View
ListView mListView = (ListView) findViewById(R.id.dataList);
/*
* Defines a SimpleCursorAdapter for the ListView
*
*/
SimpleCursorAdapter mAdapter =
new SimpleCursorAdapter(
this, // Current context
R.layout.list_item, // Layout for a single row
null, // No Cursor yet
mFromColumns, // Cursor columns to use
mToFields, // Layout fields to use
0 // No flags
);
// Sets the adapter for the view
mListView.setAdapter(mAdapter);
...
/*
* Defines the callback that CursorLoader calls
* when it's finished its query
*/
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
...
/*
* Moves the query results into the adapter, causing the
* ListView fronting this adapter to re-display
*/
mAdapter.changeCursor(cursor);
}
Delete Old Cur
public String[] mFromColumns = {
DataProviderContract.IMAGE_PICTURENAME_COLUMN
};
public int[] mToFields = {
R.id.PictureName
};
// Gets a handle to a List View
ListView mListView = (ListView) findViewById(R.id.dataList);
/*
* Defines a SimpleCursorAdapter for the ListView
*
*/
SimpleCursorAdapter mAdapter =
new SimpleCursorAdapter(
this, // Current context
R.layout.list_item, // Layout for a single row
null, // No Cursor yet
mFromColumns, // Cursor columns to use
mToFields, // Layout fields to use
0 // No flags
);
// Sets the adapter for the view
mListView.setAdapter(mAdapter);
...
/*
* Defines the callback that CursorLoader calls
* when it's finished its query
*/
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
...
/*
* Moves the query results into the adapter, causing the
* ListView fronting this adapter to re-display
*/
mAdapter.changeCursor(cursor);
}
通过实现onLoaderReset方法删除旧的数据
public void onLoaderReset(Loader<Cursor> loader) {
/*
* Clears out the adapter's reference to the Cursor.
* This prevents memory leaks.
*/
mAdapter.changeCursor(null);
}
0 0
- Loading Data in the Background 之Handling the Results
- Loading Data in the Background 之Running a Query with a CursorLoader
- Handling the Results 处理结果
- Loading Resources In The Background With A Loading Screen
- Working in the Background
- Handling Network Connections in the Background(在多任务环境下网络连接的处理)
- Handling Complexity in the Halo 2 AI
- Running in a Background Service 之Sending Work Requests to the Background Service
- The Background of Background
- Launching Tasks in the Foreground and Background
- Being productive in the background – background tasks
- How to get the JSON results in ExtJS
- Reporting the Test Results in Microsoft Test Manager
- the Data Form in Silverlight
- meta-data in the Android
- (error) LOADING Redis is loading the dataset in memory问题解决
- (error) LOADING Redis is loading the dataset in memory问题解决
- 【AndEngine】 Loading Resources in background
- easyui 的Datagrid 表头显示不全问题解决
- C#中的数字格式化、格式日期格式化
- 【Android问题】解决创建Android模拟器时提示"No system images installed for this target"的问题
- java中对于大量数据采用批量处理来提高效率
- 第六章 数据库管理
- Loading Data in the Background 之Handling the Results
- shiro的两种认证过程
- AJAX对服务器返回XML的处理方法
- centos6编译安装nginx
- Kafka sink Redis (Kafka 连接 Redis)
- 在Win7设置网络负载均衡,增加带宽
- 垃圾回收机制中,引入计数是如何实现的,内部原理是什么,怎么维持对象引用的
- ARM的7中工作模式和37个通用寄存器
- iOS性能优化:Instruments使用实战