下拉刷新控件(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.OnRefreshListener
interface 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 ...
随机推荐
- 【POJ】【1160】Post Office
DP/四边形不等式 邮局,经典的四边形不等式例题! 关于四边形不等式的学习请看 赵爽论文<动态规划加速原理之四边形不等式> 题目总结&题解:http://blog.csdn.net ...
- Leetcode#127 Word Ladder
原题地址 BFS Word Ladder II的简化版(参见这篇文章) 由于只需要计算步数,所以简单许多. 代码: int ladderLength(string start, string end, ...
- Hdu 1010 Tempter of the Bone 分类: Translation Mode 2014-08-04 16:11 82人阅读 评论(0) 收藏
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- Codeforces Round #242 (Div. 2) C题
题目链接:http://codeforces.com/contest/424/problem/C, 想来一个小时,就是做不出,都做出来了,悲剧! 分析:我们知道交换异或的顺序不影响答案! 然后就是求t ...
- codeforces #235div2 D
完全没看出是状态压缩DP, 果然没练习,之前一直再看,看来要把状压做几道了, 上代码吧:代码也是问道的 无语... #include<cstdio> #include<cstring ...
- WaitForTargetFPS
WaitForTargetFPS,是关于帧数限制的,你可能开了垂直同步,其实是防止撕裂.先说撕裂,在显示器的帧缓存会被不同步的显卡的帧缓存给替换掉,导致显示器显示到一半的时候,内存被换掉,你看到上频是 ...
- 原 JS监听回车事件
原 JS监听回车事件 发表于2年前(2014-06-04 10:16) 阅读(6101) | 评论(0) 11人收藏此文章, 我要收藏 赞0 1月16日厦门 OSC 源创会火热报名中,奖品多多哦 ...
- netaddr 0.7.12
Pythonic manipulation of IPv4, IPv6, CIDR, EUI and MAC network addresses https://pypi.python.org/pyp ...
- POJ 1338
#include<iostream> #include<stdio.h> #include<iomanip> #define MAXN 100000 using n ...
- Linux网络编程5——使用UDP协议实现群聊
引言 本文实现的功能类似于我之前所写的一篇博文(Linux之select系统调用_2),区别在于进程之间的通信方式有所不同.之前的文章中,我所使用的是管道,而本文我将会使用socket接口. 需求 客 ...