贴出布局代码:

<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的更多相关文章

  1. 分页插件思想:pc加载更多功能和移动端下拉刷新加载数据

    感觉一个人玩lol也没意思了,玩会手机,看到这个下拉刷新功能就写了这个demo! 这个demo写的比较随意,咱不能当做插件使用,基本思想是没问题的,要用就自己封装吧! 直接上代码分析下吧! 布局: & ...

  2. Google官方下拉刷新组件---SwipeRefreshLayout

    今天在Google+上看到了SwipeRefreshLayout这个名词,遂搜索了下,发现竟然是刚刚google更新sdk新增加的一个widget,于是赶紧抢先体验学习下. SwipeRefreshL ...

  3. android SwipeRefreshLayout google官方下拉刷新控件

    下拉刷新功能之前一直使用的是XlistView很方便我前面的博客有介绍 SwipeRefreshLayout是google官方推出的下拉刷新控件使用方法也比较简单 今天就来使用下SwipeRefres ...

  4. 第一个开源控件:Google 官方下拉刷新控件 SwipeRefreshLayout 强化版,支持上拉刷新

    最近比较闲,所以趁着这时间撸了个SwipeRefreshLayout的加强版,Github地址. 原版只支持下拉刷新,强化之后支持上拉刷新和一进入页面就加载刷新,整个控件的加载动画是一致的,毫无违和感 ...

  5. listView下拉刷新加载数据

    这个下拉效果在网上最早的例子恐怕就是Johan Nilsson的实现,http://johannilsson.com/2011/03/13/android-pull-to-refresh-update ...

  6. 使用谷歌提供的SwipeRefreshLayout下拉控件进行下拉刷新的实现数据的刷新

    package com.loaderman.swiperefreshdemo; import android.os.Bundle; import android.os.Handler; import ...

  7. 下拉刷新控件(5)SwipeRefreshLayout官方教程(下)响应刷新事件

    http://developer.android.com/training/swipe/respond-refresh-request.html This lesson shows you how t ...

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

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

  9. Android PullToRefresh (GridView 下拉刷新上拉加载)

    做这个需要自己去git hub上下载个pull-to-refresh 里面有个library为依赖包自己导到自己的项目中 (下载地址:https://github.com/chrisbanes/And ...

随机推荐

  1. linux环境(CentOS-6.7)下redis集群的搭建全过程

    linux环境下redis集群的搭建全过程: 使用mount命令将光盘挂载到/mnt/cdrom目录下: [root@hadoop03 ~]# mount -t iso9660 -o ro /dev/ ...

  2. static final的理解

    static: static静态,可以修饰类,成员变量,成员方法,代码块.static修饰的成员变量和方法独立于该类的任何对象,也就是被类的所有成员共享,这要这个类被加载,虚拟机就能根据类名在运行时数 ...

  3. CRLF CSRF XSS

    http://baike.baidu.com/link?url=BXWN2I6J23thrrm6JoEnAYvmNqp83llyaydaj5RYkq--tuJKSFuMuDMIoTPnKjthRUm3 ...

  4. PacBio长reads的大基因组组装

    原文链接:Large Genome Assembly with PacBio Long Reads 可以以多种方式利用PacBio长reads来生成和改进大型基因组的de novo组装. 你可以用几种 ...

  5. 有用的dede表单代码

    <form action="" class="demoform">                <table>             ...

  6. android优化从网络中加载图片速度。。

    从网络中加载图片主要要注意两个方面的问题: 1.内存管理:图片占的内存很大,假如图片数量多,很容易让系统抛出out of memory的异常. 同时我们也要注意不同android版本中内存管理的区别. ...

  7. CentOS 6.x安装配置

    简述 VMware可以创建多个虚拟机,每个虚拟机上都可以安装各种类型的操作系统.安装方法也有很多种.下面,主要以ISO镜像安装为例,介绍CentOS 6.x的安装过程及相关的参数设置. 简述 创建虚拟 ...

  8. CF---(452)A. Eevee

    A. Eevee time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...

  9. C语言实现统计字符个数

    #include<stdio.h> int main() {     int sz[10]={0},zm[26]={0},z[26]={0},i,space=0,e=0,t=0;      ...

  10. 5月23日 JavaScript练习:累加求和

    第一种方法: 第二种方法: