SwipeRefreshLayout是Google在support v4 19.1版本的library更新的一个下拉刷新组件,实现刷新效果更方便。

使用如下:

1.先下载android-support-v4.jar最新版本,之前的版本是没有SwipeRefreshLayout下拉刷新控件的,如果已经更新,此步骤可省略。

2.在xml文件中引用android.support.v4.widget.SwipeRefreshLayout控件,在里面可以放置任何一个控件,例如ListView,gridview等。

     <android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent" > <ListView
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
</android.support.v4.widget.SwipeRefreshLayout>

3.在java文件中使用。

 /**
* 主页
* @author w.w
*/
public class MainActivity extends Activity implements SwipeRefreshLayout.OnRefreshListener { /**
* 给ListView添加下拉刷新
*/
private SwipeRefreshLayout swipeLayout; /**
* ListView
*/
private ListView listView; /**
* ListView适配器
*/
private ListViewAdapter adapter; private List<ItemInfo> infoList; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); swipeLayout = (SwipeRefreshLayout) this.findViewById(R.id.swipe_refresh);
swipeLayout.setOnRefreshListener(this); // 顶部刷新的样式
swipeLayout.setColorScheme(android.R.color.holo_red_light, android.R.color.holo_green_light,
android.R.color.holo_blue_bright, android.R.color.holo_orange_light); infoList = new ArrayList<ItemInfo>();
ItemInfo info = new ItemInfo();
info.setName("coin");
infoList.add(info);
listView = (ListView) this.findViewById(R.id.listview);
adapter = new ListViewAdapter(this, infoList);
listView.setAdapter(adapter);
} public void onRefresh() {
new Handler().postDelayed(new Runnable() {
public void run() {
swipeLayout.setRefreshing(false);
ItemInfo info = new ItemInfo();
info.setName("coin-refresh");
infoList.add(info);
adapter.notifyDataSetChanged();
}
}, 500);
}
}

demo下载地址:http://download.csdn.net/detail/xue_wei_love/7135315

【转】google推出的SwipeRefreshLayout下拉刷新用法的更多相关文章

  1. google推出的SwipeRefreshLayout下拉刷新用法

    使用如下: 1.先下载android-support-v4.jar最新版本,之前的版本是没有SwipeRefreshLayout下拉刷新控件的,如果已经更新,此步骤可省略. 2.在xml文件中引用an ...

  2. Android零基础入门第72节:SwipeRefreshLayout下拉刷新

    在实际开发中,经常都会遇到下拉刷新.上拉加载更多的情形,这一期就一起来学习Android系统的SwipeRefreshLayout下拉刷新组件. 一.SwipeRefreshLayout简介 Swip ...

  3. Android之SwipeRefreshLayout下拉刷新组件

    SwipeRefreshLayout概述 SwipeRefrshLayout是Google官方更新的一个Widget,可以实现下拉刷新的效果.该控件集成自ViewGroup在support-v4兼容包 ...

  4. google官方提供的下拉刷新控件SwipeRefreshLayout

    摘自:http://www.stormzhang.com/android/2014/03/29/android-swiperefreshlayout/ SwipeRefreshLayout Swipe ...

  5. Android SwipeRefreshLayout 下拉刷新——Hi_博客 Android App 开发笔记

    以前写下拉刷新 感觉好费劲,要判断ListView是否滚到顶部,还要加载头布局,还要控制 头布局的状态,等等一大堆.感觉麻烦死了.今天学习了SwipeRefreshLayout 的用法,来分享一下,有 ...

  6. SwipeRefreshLayout下拉刷新

    1.SwipeRefreshLayout是Google在support v4 19.1版本的library更新的一个下拉刷新组件,实现刷新效果更方便. 弊端:只有下拉 //设置刷新控件圈圈的颜色 sw ...

  7. SwipeRefreshLayout下拉刷新简单用例

    自己的下拉刷新组件 下拉刷新并自动添加数据 MainActivity package com.shaoxin.myswiperefreshlayout; import android.graphics ...

  8. Android --SwipeRefreshLayout 下拉刷新

    1.Layout <android.support.v4.widget.SwipeRefreshLayout android:id="@+id/id_swipe_ly" an ...

  9. 谷歌官方SwipeRefreshLayout下拉刷新的用法。

    <Android SwipeRefreshLayout:谷歌官方SDK包中的下拉刷新> 下拉刷新在如今移动开发中应用如此广泛和普遍,以至于谷歌干脆在SDK中给予支持.在android-su ...

随机推荐

  1. HDU 2026 首字母变大写

    #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int ma ...

  2. linearlayout 水平垂直居中

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools=&q ...

  3. C# "error CS1729: 'XXClass' does not contain a constructor that takes 0 arguments"的解决方案

    出现这种错误的原因时,没有在子类的构造函数中指出仅有带参构造函数的父类的构造参数. 具体来讲就是: 当子类要重用父类的构造函数时, C# 语法通常会在子类构造函数后面调用 : base( para_t ...

  4. 多数据源问题--Spring+Ibatis 访问多个数据源(非分布式事务)

    有的时候,我在一个工程中需要访问两个以上的数据源,尤其是在系统集成的时候,以下是我在系统集成的时候遇到的情况,我的工程的架构是:spring2.0+ibatis2.0+struts1.2. 数据库是o ...

  5. Oracle优化器介绍

    Oracle优化器介绍 本文讲述了Oracle优化器的概念.工作原理和使用方法,兼顾了Oracle8i.9i以及最新的10g三个版本.理解本文将有助于您更好的更有效的进行SQL优化工作. RBO优化器 ...

  6. cocos2dx 水波纹Shader

    // on "init" you need to initialize your instance bool HelloWorld::init() { ////////////// ...

  7. struts2类库下载

    struts2开发包下载 到http://struts.apache.org/download.cgi#struts2014下载struts-2.x.x-all.zip,目前最新版为2.1.6.下载完 ...

  8. Yarn通信过程

    yarn包括两块,一个是ResourceManager,主要的作用是管理集群上的资源,目前hadoop版本上,管理的只有cpu和内存. 另外一个叫NodeManager,这上面会跑我们的程序,叫App ...

  9. js运动 淡入淡出

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  10. T-SQL 变量

    T-SQL变量 变量的种类: 在T-SQL中,变量按生存范围可以分为全局变量(Global Variable)和局部变量(Local Variable) 1.全局变量是由系统定义的,在整个SQL Se ...