使用Google API 下拉刷新或者增加数据 SwipeRefreshLayout
贴出布局代码:
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/id_swipe_ly"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:clickable="true">
<TextView
android:id="@+id/id_listview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮"/>
</LinearLayout>
</android.support.v4.widget.SwipeRefreshLayout>
根据我的不完全实验 SwipeRefreshLayout 内可以使用所有控件,但是前提是必须在不能点击的控件上 写上这个 android:clickable=“true” ,不然会有些问题。虽然数据依然能加载出来但是加载图标就会闪现(可以随意尝试)
使用这个 SwipeRefreshLayout 必须实现这个接口:
public class MainActivity extends Activity implements SwipeRefreshLayout.OnRefreshListener
然后会自动生成它的一个方法:
public void onRefresh() { }
可以在这里面写你的一系列操作,但是不建议写耗时的操作,可以写一个Handler 来接收信息 并加载信息。 全部代码:
布局文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" > <android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/id_swipe_ly"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:clickable="true">
<TextView
android:id="@+id/id_listview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮"/>
</LinearLayout>
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>
MainAcitivity
public class MainActivity extends Activity implements SwipeRefreshLayout.OnRefreshListener { private static final int REFRESH_COMPLETE = 0X110;
private SwipeRefreshLayout mSwipeLayout;
private TextView mListView; private Handler mHandler = new Handler() {
public void handleMessage(android.os.Message msg) {
switch (msg.what) {
case REFRESH_COMPLETE: mListView.setText("猪猪侠");
mSwipeLayout.setRefreshing(false);
break; }
} ;
}; protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); mListView = (TextView) findViewById(R.id.id_listview);
mSwipeLayout = (SwipeRefreshLayout) findViewById(R.id.id_swipe_ly); mSwipeLayout.setOnRefreshListener(this);
mSwipeLayout.setColorScheme(android.R.color.holo_blue_bright, android.R.color.holo_green_light,
android.R.color.holo_orange_light, android.R.color.holo_red_light);
} public void onRefresh() { mHandler.sendEmptyMessageDelayed(REFRESH_COMPLETE, 2000);
}
}
至此就可以完成了 一个简单的刷新!
使用Google API 下拉刷新或者增加数据 SwipeRefreshLayout的更多相关文章
- 分页插件思想:pc加载更多功能和移动端下拉刷新加载数据
感觉一个人玩lol也没意思了,玩会手机,看到这个下拉刷新功能就写了这个demo! 这个demo写的比较随意,咱不能当做插件使用,基本思想是没问题的,要用就自己封装吧! 直接上代码分析下吧! 布局: & ...
- Google官方下拉刷新组件---SwipeRefreshLayout
今天在Google+上看到了SwipeRefreshLayout这个名词,遂搜索了下,发现竟然是刚刚google更新sdk新增加的一个widget,于是赶紧抢先体验学习下. SwipeRefreshL ...
- android SwipeRefreshLayout google官方下拉刷新控件
下拉刷新功能之前一直使用的是XlistView很方便我前面的博客有介绍 SwipeRefreshLayout是google官方推出的下拉刷新控件使用方法也比较简单 今天就来使用下SwipeRefres ...
- 第一个开源控件:Google 官方下拉刷新控件 SwipeRefreshLayout 强化版,支持上拉刷新
最近比较闲,所以趁着这时间撸了个SwipeRefreshLayout的加强版,Github地址. 原版只支持下拉刷新,强化之后支持上拉刷新和一进入页面就加载刷新,整个控件的加载动画是一致的,毫无违和感 ...
- listView下拉刷新加载数据
这个下拉效果在网上最早的例子恐怕就是Johan Nilsson的实现,http://johannilsson.com/2011/03/13/android-pull-to-refresh-update ...
- 使用谷歌提供的SwipeRefreshLayout下拉控件进行下拉刷新的实现数据的刷新
package com.loaderman.swiperefreshdemo; import android.os.Bundle; import android.os.Handler; import ...
- 下拉刷新控件(5)SwipeRefreshLayout官方教程(下)响应刷新事件
http://developer.android.com/training/swipe/respond-refresh-request.html This lesson shows you how t ...
- 下拉刷新控件(4)SwipeRefreshLayout官方教程(上)如何在应用中使用它
http://developer.android.com/training/swipe/add-swipe-interface.html 1,在布局xml和代码中使用它 2,在menu中添加它 The ...
- Android PullToRefresh (GridView 下拉刷新上拉加载)
做这个需要自己去git hub上下载个pull-to-refresh 里面有个library为依赖包自己导到自己的项目中 (下载地址:https://github.com/chrisbanes/And ...
随机推荐
- [C++]访问控制与继承(public,protect,private) 有时间再整理!!!
http://www.cnblogs.com/chio/archive/2007/06/11/779408.html http://www.cnblogs.com/SelaSelah/archive/ ...
- 阿里云+wordpress搭建个人博客网站
[正文] 在阿里云上搭建使用个人博客主要分为以下几个步骤: 1.购买阿里云ECS主机 2.购买域名 3.申请备案 4.环境配置 5.安装wordpress 6.域名解析 声明一下,本人对服务器端的知识 ...
- HEVC编解码优化信息
hevc解码GPU优化: 1.This GPU acceleration has opened up the possibility of playing a Full-HD (1080p) at 6 ...
- el 和 fmt 常用
EL表达式入门 转自 http://blog.chinaunix.net/uid-9789791-id-1997374.html 隐含对象: pageContext: pageContext对象 pa ...
- BOM头的来源
类似WINDOWS自带的记事本等软件,在保存一个以UTF-8编码的文件时,会在文件开始的地方插入三个不可见的字符(0xEF 0xBB 0xBF,即BOM).它是一串隐藏的字符,用于让记事本等编辑器识别 ...
- linux下动态链接库.so文件 静态链接库.a文件创建及使用
转摘网址为:http://www.cnblogs.com/fengyv/archive/2012/08/10/2631313.html Linux下文件的类型是不依赖于其后缀名的,但一般来讲: ...
- 大S《美容大王》内容80%都是没用的东西
揭20位明星真实人品 我在她大陆的企划公司工作过,见过她N次了,对人态度蛮不错的,而且很爱开玩笑,但感觉很假很抠门.只要一回公司她就黏着请她吃饭.她很主动很霸道,她和周渝民交往,原因之一就是周什么都听 ...
- Openvpn 安装简述
1.固定本地IP地址 vim /etc/sysconfig/network-scripts/ifcfg-eth0 2.同步时间.安装ntpd yum install ntpddate netupda ...
- graph-tool文档(一)- 快速开始使用Graph-tool - 3.图的过滤
目录: 图的过滤 图视图 -- 组合图视图 名词解释: filter:过滤 mask:屏蔽 inverted parameter:倒参数 overhead:开销 minimum spanning tr ...
- VirtualBox相关问题总结
欢迎关注我的社交账号: 邮箱: jiangxinnju@163.com 博客园地址: http://www.cnblogs.com/jiangxinnju GitHub地址: https://gith ...