效果预览图:

下载地址:https://github.com/chrisbanes/Android-PullToRefresh

activity_main.xml:

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.zzw.testpulltorefresh.MainActivity" > <com.handmark.pulltorefresh.library.PullToRefreshListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent" /> </RelativeLayout>

MainActuvity.java:

 package com.zzw.testpulltorefresh;

 import java.util.ArrayList;
import java.util.Date; import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode;
import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener;
import com.handmark.pulltorefresh.library.PullToRefreshListView; import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.SystemClock;
import android.widget.Adapter;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast; public class MainActivity extends Activity { private PullToRefreshListView listView;
private ArrayList<String> data;
private ArrayAdapter adapter;
private int count = 0; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); data = new ArrayList<String>(); listView = (PullToRefreshListView) findViewById(R.id.listView);
// 设置向下滑动时刷新
listView.setMode(Mode.PULL_FROM_START);
// 支持下拉和上拉 listView.setMode(Mode.BOTH);
// 设置监听
listView.setOnRefreshListener(new OnRefreshListener<ListView>() { @Override
public void onRefresh(PullToRefreshBase<ListView> refreshView) {
// 在这完成业务逻辑
new MyAsyncTask().execute();
}
}); adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, data);
listView.setAdapter(adapter); // 设置如果数据为空的时候显示什么
TextView textView = new TextView(this);
textView.setText("请下拉刷新");
listView.setEmptyView(textView);
} private class MyAsyncTask extends AsyncTask { @Override
protected void onPreExecute() {
// 开始刷新
listView.setRefreshing();
} @Override
protected Object doInBackground(Object... params) {
// 假设耗时时间为3秒
SystemClock.sleep(3000);
return count++;
} @Override
protected void onPostExecute(Object result) { data.add(0, result + "");
adapter.notifyDataSetChanged(); // 设置标签
listView.setLastUpdatedLabel("最后更新新的时间:" + new Date()); // 刷新完成
listView.onRefreshComplete();
Toast.makeText(getApplicationContext(), "加载成功", 0).show();
}
} }

下拉刷新--第三方开源--PullToRefresh的更多相关文章

  1. 水滴效果的下拉刷新--第三方开源 开源--WaveSwipeRefreshLayout

    下载地址:https://github.com/recruit-lifestyle/WaveSwipeRefreshLayout 直接把代码复制到你的项目于即可使用: 使用: 在xml中: <j ...

  2. Android下拉刷新控件--PullToRefresh的简单使用

    Android中很多时候都会用到上下拉刷新,这是一个很常用的功能,Android的v4包中也为我们提供了一种原生的下拉刷新控件--SwipeRefreshLayout,可以用它实现一个简洁的刷新效果, ...

  3. 清新大气的ListView下拉上拉刷新--第三方开源--PullDownListView

    下载地址:https://github.com/guojunyi/PullDownListView 使用: xml: <com.pulldownlistview.PullDownListView ...

  4. iOS开源项目推荐|下拉刷新

    MJRefresh - 仅需一行代码就可以为UITableView或者CollectionView加上下拉刷新或者上拉刷新功能.可以自定义上下拉刷新的文字说明. CBStoreHouseRefresh ...

  5. 【转载】 Android PullToRefresh (ListView GridView 下拉刷新) 使用详解

    Android下拉刷新pullToRefreshListViewGridView 转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/3 ...

  6. Android PullToRefresh (ListView GridView 下拉刷新) 使用详解

    转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/38238749,本文出自:[张鸿洋的博客] 群里一哥们今天聊天偶然提到这个git ...

  7. Android PullToRefresh (ListView GridView 下拉刷新) 使用详解 (转载)

    最近项目用到下拉刷新,上来加载更多,这里对PullToRefresh这控件进行了解和使用. 以下内容转载自:http://blog.csdn.net/lmj623565791/article/deta ...

  8. Android研究之手PullToRefresh(ListView GridView 下拉刷新)使用具体解释

     群里一哥们今天聊天偶然提到这个git hub上的控件:pull-to-refresh ,有兴趣的看下,样例中的功能极其强大,支持非常多控件.本篇博客具体给大家介绍下ListView和GridVi ...

  9. 【转】Android PullToRefresh (ListView GridView 下拉刷新) 使用详解

    最近项目用到下拉刷新,上来加载更多,这里对PullToRefresh这控件进行了解和使用. 以下内容转载自:http://blog.csdn.net/lmj623565791/article/deta ...

随机推荐

  1. UITableView加载显示更多内容

    #import <UIKit/UIKit.h> @interface ViewController : UIViewController @end #import "ViewCo ...

  2. 沈逸老师PHP魔鬼特训笔记(6)--巫术与骨架

    PHP最牛逼的特性之一除了懒人函数,还有一些魔法函数. 首先我们来认识下__tostring,通过一个巫术方法,我们吧实例转化过后的类,直接当字符串输出.结合我们前面所做的功能,我们在类里面加上这个函 ...

  3. 不错的jQuery图表插件 .

    很多时候我们需要在网页中显示数据统计报表,从而能很直观地了解数据的走向,更好地帮助决策分析.今天就给大家分享几个个人觉得好用的jQuery图表插件,这几个图表插件使用起来非常方便,而且挺灵活的,相信大 ...

  4. linux初学 :linux 常用命令(一)

    首先,是关机/重启命令,仅在虚拟机时使用,实际工作中用不到 reboot 一般不跟参数使用,输入指令即可重启 shutdown 一般需要跟参数,例: shutdown -r 延时多少分钟重启,一般使用 ...

  5. 2000 Asia shanghai Dance Dance Revolution

    思路:dp[i][x][y]表示第i个序列中,右脚在x位置,左脚在y位置时,其最小花费. 那么dp[i][x][y]=min(dp[i-1][a[i]][y]+cost[a[i]][x],dp[i-1 ...

  6. Miniui updateRow更改列字段值

    当UPC等于upccode时,更改列Scanned+1 //先grid.findRow找到UPC等于upccode的行对象 var row = grid.findRow(function (row) ...

  7. Ubuntu 16.04 - python3 安装mysql驱动

    阿西吧,今天碰到一件特别蛋疼的事,给Ubuntu安装Python的MySQL驱动,驱动显示安装成功了 pip install mysql-connector 但是 在程序中导入,老是报错. Trace ...

  8. Eclipse中调试技巧

    1.打印输出 System.outprintln(“执行了此程序"); 2.运用Log方法: 示例 Log.d("myDubug",  "myFirstDebu ...

  9. C# 线程锁Lock 死锁

    使用lock场景 多线程环境中,不使用lock锁,会形成竞争条件,导致错误. 使用lock 锁 可以保证当有线程操作某个共享资源时,其他线程必须等待直到当前线程完成操作. 即是多线程环境,如果一个线程 ...

  10. linux中利用iptables+geoip过滤指定IP

    1. 前提条件 iptables >= 1.4.5 kernel-devel >= 3.7 2.  安装依赖包  代码如下 复制代码 # yum install gcc gcc-c++ m ...