SwipeRefreshLayout+AsyncHttpClient 实现异步Http请求的下拉刷新
2016-03-10 14:12
531 查看
感谢原文作者:http://stormzhang.github.io/android/2014/03/29/android-swiperefreshlayout/
API doc:http://developer.android.com/reference/android/support/v4/widget/SwipeRefreshLayout.html
首先须把你的support library的版本升级到19.1或更新
界面:
逻辑代码:
可以结合异步AsyncHttpClient请求一起使用,在其onSuccess中调用
API doc:http://developer.android.com/reference/android/support/v4/widget/SwipeRefreshLayout.html
首先须把你的support library的版本升级到19.1或更新
界面:
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/swipe_container" android:layout_width="match_parent" android:layout_height="match_parent" > <ScrollView android:layout_width="match_parent" android:layout_height="wrap_content" > <TextView android:id="@+id/textView1" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:paddingTop="10dp" android:text="@string/swipe_to_refresh" android:textSize="20sp" android:textStyle="bold" /> </ScrollView> </android.support.v4.widget.SwipeRefreshLayout>
逻辑代码:
tv = (TextView)findViewById(R.id.textView1); swipeRefreshLayout = (SwipeRefreshLayout)findViewById(R.id.swipe_container); //设置刷新时动画的颜色,可以设置4个 swipeRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_light, android.R.color.holo_red_light, android.R.color.holo_orange_light, android.R.color.holo_green_light); swipeRefreshLayout.setOnRefreshListener(new OnRefreshListener() { @Override public void onRefresh() { tv.setText("正在刷新"); // TODO Auto-generated method stub new Handler().postDelayed(new Runnable() { @Override public void run() { // TODO Auto-generated method stub tv.setText("刷新完成"); swipeRefreshLayout.setRefreshing(false); } }, 6000);
可以结合异步AsyncHttpClient请求一起使用,在其onSuccess中调用
swipeRefreshLayout.setRefreshing(false);方法来向用户提示刷新完成,亲测有效。
相关文章推荐
- 安卓之HTTPSMD5加密
- C# 的TCPClient异步连接与异步读数据
- python 发起HTTP请求
- 解决HTTP Status 500 - java.lang.NoClassDefFoundError: org/apache/commons/el/ExpressionEvaluatorImpl报错
- TCP/IP通信程序设计方式
- Linux服务器上监控网络带宽的18个常用命令
- http客户端通信 (java原生)
- angularjs flask跨域问题 XMLHttpRequest cannot load. No 'Access-Control-Allow-Origin'
- 安卓之检测网络
- ndroid获取网络时间及时间日期显示格式
- TCP/IP知识总结(TCP/IP协议族读书笔记四)
- tcp-ip-状态详解(转)
- Java多线程TCP客户端与服务器间使用Socket通信
- 网络编程
- 博客搬迁至http://blog.lizorn.com/
- 并发ping监测网络状态
- tcpcopy 1.0 安装使用
- 简单的异步HTTP服务端和客户端
- TCP和UDP
- androd 网络请求方式对比与详解