下拉刷新控件(5)SwipeRefreshLayout官方教程(下)响应刷新事件
http://developer.android.com/training/swipe/respond-refresh-request.html
This lesson shows you how to update your app when the user requests a manual refresh, whether the user triggers the refresh with a swipe gesture or by using the action bar refresh action.
Respond to the Refresh Gesture
When the user makes a swipe gesture, the system displays the progress indicator and calls your app's callback method. Your callback method is responsible for actually updating the app's data.
To respond to the refresh gesture in your app, implement the SwipeRefreshLayout.OnRefreshListenerinterface and its onRefresh() method. The onRefresh() method is invoked when the user performs a swipe gesture.
You should put the code for the actual update operation in a separate method, and call that update method from your onRefresh() implementation. That way, you can use the same update method to perform the update when the user triggers a refresh from the action bar.
Your update method calls setRefreshing(false) when it has finished updating the data. Calling this method instructs the SwipeRefreshLayout to remove the progress indicator and update the view contents.
For example, the following code implements onRefresh() and invokes the method myUpdateOperation()to update the data displayed by the ListView:
/*
* Sets up a SwipeRefreshLayout.OnRefreshListener that is invoked when the user
* performs a swipe-to-refresh gesture.
*/
mySwipeRefreshLayout.setOnRefreshListener(
new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
Log.i(LOG_TAG, "onRefresh called from SwipeRefreshLayout"); // This method performs the actual data-refresh operation.
// The method calls setRefreshing(false) when it's finished.
myUpdateOperation();
}
}
);
Respond to the Refresh Action
If the user requests a refresh by using the action bar, the system calls the onOptionsItemSelected()method. Your app should respond to this call by displaying the progress indicator and refreshing the app's data.
To respond to the refresh action, override onOptionsItemSelected(). In your override method, trigger theSwipeRefreshLayout progress indicator by calling setRefreshing() with the value true, then perform the update operation. Once again, you should be doing the actual update in a separate method, so the same method can be called whether the user triggers the update with a swipe or by using the action bar. When the update has finished, call setRefreshing(false) to remove the refresh progress indicator.
The following code shows how to respond to the request action:
/*
* Listen for option item selections so that we receive a notification
* when the user requests a refresh by selecting the refresh action bar item.
*/
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { // Check if user triggered a refresh:
case R.id.menu_refresh:
Log.i(LOG_TAG, "Refresh menu item selected"); // Signal SwipeRefreshLayout to start the progress indicator
mySwipeRefreshLayout.setRefreshing(true); // Start the refresh background task.
// This method calls setRefreshing(false) when it's finished.
myUpdateOperation(); return true;
} // User didn't trigger a refresh, let the superclass handle this action
return super.onOptionsItemSelected(item); }
Note:
When the user triggers a refresh with a swipe action as described in Respond to the Refresh Gesture, you do not need to call setRefreshing(). The SwipeRefreshLayout widget takes care of displaying the progress indicator and removing it when the update has finished. However, if the update is triggered by any means other than a swipe gesture, you need to explicitly turn the progress indicator on with setRefreshing(). The method which actually refreshes the data calls setRefreshing(false) to signal that the update is finished.
下拉刷新控件(5)SwipeRefreshLayout官方教程(下)响应刷新事件的更多相关文章
- 下拉刷新控件(4)SwipeRefreshLayout官方教程(上)如何在应用中使用它
http://developer.android.com/training/swipe/add-swipe-interface.html 1,在布局xml和代码中使用它 2,在menu中添加它 The ...
- [Swift通天遁地]二、表格表单-(4)使用系统自带的下拉刷新控件,制作表格的下拉刷新效果
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- thinter中combobox下拉选择控件(九)
combobox控件,下拉菜单控件 combobox控件在tkinter中的ttk下 简单的实现下: import tkinter from tkinter import ttk # 导入ttk模块, ...
- 415 DOM 查找列表框、下拉菜单控件、对表格元素/表单控件进行增删改操作、创建元素并且复制节点与删除、 对表格操作、通用性和标准的事件监听方法(点击后弹窗效果以及去掉效果)
DOM访问列表框.下拉菜单的常用属性: form.length.options.selectedindex.type 使用options[index]返回具体选项所对应的常用属性:defa ...
- tkinter中combobox下拉选择控件(九)
combobox控件,下拉菜单控件 combobox控件在tkinter中的ttk下 简单的实现下: import tkinter from tkinter import ttk # 导入ttk模块, ...
- FineReport——JS二次开发(隐藏下拉框控件的倒三角)
在对FR控件进行二次开发的过程中,需要自定义样式,比如下拉框控件带有自动检索的功能,但是又希望它的显示样式如同文本框一样,这时就需要隐藏多余的部分. 在对在线文档的查阅中可以发现很多选择器适用于多种控 ...
- DevExpress的下拉框控件ComboxBoxEdit怎样绑定键值对选项
场景 DevExpress的下拉框控件ComboBoxEdit控件的使用: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/1028 ...
- DevExpress的下拉框控件ComboBoxEdit控件的使用
场景 Winform控件-DevExpress18下载安装注册以及在VS中使用: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/1 ...
- DevExpress的下拉框控件LookUpEdit的使用、添加item选项值、修改默认显示值
场景 Winform控件-DevExpress18下载安装注册以及在VS中使用: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/1 ...
随机推荐
- 【BZOJ】【3676】【APIO2014】回文串
回文自动机/Manacher+SA 这道题可以用Manacher找出本质不同的回文串(令max增大的所有回文串),然后再用SA跑出来有多少相同. 还有一种做法就是回文自动机(Orz Hzwer)的裸题 ...
- 在线最优化求解(Online Optimization)之五:FTRL
在线最优化求解(Online Optimization)之五:FTRL 在上一篇博文中中我们从原理上定性比较了L1-FOBOS和L1-RDA在稀疏性上的表现.有实验证明,L1-FOBOS这一类基于梯度 ...
- HDOJ 1220 Cube
CubeTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
- vuforia 结合 unity3d 开发 AR 的 androidAPP 总结
原地址:https://software.intel.com/zh-cn/blogs/2014/07/09/vuforia-unity3d-ar-androidapp/?utm_campaign=CS ...
- iOS字符串大小转换
NSString *test = @"Hello World"; // 小写 NSString *lower = [test lowercaseSt ...
- 深入浅出ES6(十四):let和const
作者 Jason Orendorff github主页 https://github.com/jorendorff 回溯到1995年,当Brendan Eich在设计第一版JavaScript时, ...
- ***codeigniter 2.2 affected_rows()返回值不准确
http://blog.icodeu.com/?p=596 问题描述今天在完成一个项目调用想要检验一下计划插入的数据是否都正常插入了.调用insert_batch()方法插入一百多条数据的时候发现af ...
- ExtJs布局之BOX
<!DOCTYPE html> <html> <head> <title>ExtJs</title> <meta http-equiv ...
- 【hdu3065-病毒侵袭持续中】AC自动机
题意:给定一些只含大写字母的病毒串,再给一个文本串,问文本串中每个病毒串各出现了多少次. 题解: 就是用AC自动机,在每个节点末尾有个id记录是哪个单词的末尾,然后如果同时是多个单词的末尾就用一个ne ...
- Core Animation2-CABasicAnimation
CABasicAnimation是CAPropertyAnimation的子类,使用它可以实现一些基本的动画效果,它可以让CALayer的某个属性从某个值渐变到另一个值.下面就用CABasicAnim ...