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官方教程(下)响应刷新事件的更多相关文章

  1. 下拉刷新控件(4)SwipeRefreshLayout官方教程(上)如何在应用中使用它

    http://developer.android.com/training/swipe/add-swipe-interface.html 1,在布局xml和代码中使用它 2,在menu中添加它 The ...

  2. [Swift通天遁地]二、表格表单-(4)使用系统自带的下拉刷新控件,制作表格的下拉刷新效果

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  3. thinter中combobox下拉选择控件(九)

    combobox控件,下拉菜单控件 combobox控件在tkinter中的ttk下 简单的实现下: import tkinter from tkinter import ttk # 导入ttk模块, ...

  4. 415 DOM 查找列表框、下拉菜单控件、对表格元素/表单控件进行增删改操作、创建元素并且复制节点与删除、 对表格操作、通用性和标准的事件监听方法(点击后弹窗效果以及去掉效果)

    DOM访问列表框.下拉菜单的常用属性: form.length.options.selectedindex.type       使用options[index]返回具体选项所对应的常用属性:defa ...

  5. tkinter中combobox下拉选择控件(九)

    combobox控件,下拉菜单控件 combobox控件在tkinter中的ttk下 简单的实现下: import tkinter from tkinter import ttk # 导入ttk模块, ...

  6. FineReport——JS二次开发(隐藏下拉框控件的倒三角)

    在对FR控件进行二次开发的过程中,需要自定义样式,比如下拉框控件带有自动检索的功能,但是又希望它的显示样式如同文本框一样,这时就需要隐藏多余的部分. 在对在线文档的查阅中可以发现很多选择器适用于多种控 ...

  7. DevExpress的下拉框控件ComboxBoxEdit怎样绑定键值对选项

    场景 DevExpress的下拉框控件ComboBoxEdit控件的使用: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/1028 ...

  8. DevExpress的下拉框控件ComboBoxEdit控件的使用

    场景 Winform控件-DevExpress18下载安装注册以及在VS中使用: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/1 ...

  9. DevExpress的下拉框控件LookUpEdit的使用、添加item选项值、修改默认显示值

    场景 Winform控件-DevExpress18下载安装注册以及在VS中使用: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/1 ...

随机推荐

  1. Leetcode#92 Reverse Linked List II

    原题地址 第一步,找到将要翻转的位置,记录翻转部分前一个节点(prev) 第二步,翻转,记录翻转完成后这部分的首(reverseHead)和尾(reverseTail),以及翻转部分之后的一个节点(p ...

  2. mysql Communications link failure,C3p0的参数详解

    MySQL默认一个连接空闲8小时候就会自动断开,而这时程序以为连接还能使用,然后在使用的时候就会出现Communications link failure异常. 这时需要进行两步设置,有时候只设置My ...

  3. ASP.NET为图片加上水印

    为我们发布的图片加上一个水印,也是我们经常要做的事情,那怎么样来做呢,下面就一步步开始吧 首先是一个制作水印的类:ImageHandler,代码如下: using System; using Syst ...

  4. 实现WMSservice的时候,出现边缘的点或icon被切断的情况

    可以通过为实际查询的boundary加一个buffer,使查询的范围比指定的大一点点,这样就会使tile之间在查询的时候有一定的重叠. 如:Geometry queryBoundary = JTS.t ...

  5. this的使用、继承、super

    1.this的使用 1)可以用于区分局部变量 Person(int age,string name) { this.age=age; this.name=name; } 2)构造方法中,用this调用 ...

  6. visual studio 2012 Github

    前言 一直以来都想使用Git来管理自己平时积累的小代码,就是除了工作之外的代码了.有时候自己搞个小代码,在公司写了,就要通过U盘或者网盘等等一系列工具进行Copy,然后回家才能继续在原来的基础上作业. ...

  7. Codeforces 414C Mashmokh and Reverse Operation

    题意:给你2^n个数,每次操作将其分成2^k份,对于每一份内部的数进行翻转,每次操作完后输出操作后的2^n个数的逆序数. 解法:2^n个数,可以联想到建立一棵二叉树的东西,比如  2,1,4,3就可以 ...

  8. Activity学习(三)——跳转传值

    Activity跳转与传值,主要是通过Intent类来连接多个Activity,以及传递数据.   Intent是Android一个很重要的类.Intent直译是“意图”,什么是意图呢?比如你想从这个 ...

  9. Win7 _Object_header 中的 TypeIndex

    Win7 比较 xp下ObjectHeader中的内容有所变化,xp直接在OBJECT_HEADER里保存了POBJECT_TYPE指针,而Win7中把所有的对象类型放在了一个表里,这个表叫做ObTy ...

  10. lintcode: 旋转图像

    旋转图像 给定一个N×N的二维矩阵表示图像,90度顺时针旋转图像. 解题 顺时针旋转90度 就是 上下翻转,再主对角对折 public class Solution { /** * @param ma ...