下拉刷新--第三方开源--PullToRefresh
效果预览图:
下载地址: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的更多相关文章
- 水滴效果的下拉刷新--第三方开源 开源--WaveSwipeRefreshLayout
下载地址:https://github.com/recruit-lifestyle/WaveSwipeRefreshLayout 直接把代码复制到你的项目于即可使用: 使用: 在xml中: <j ...
- Android下拉刷新控件--PullToRefresh的简单使用
Android中很多时候都会用到上下拉刷新,这是一个很常用的功能,Android的v4包中也为我们提供了一种原生的下拉刷新控件--SwipeRefreshLayout,可以用它实现一个简洁的刷新效果, ...
- 清新大气的ListView下拉上拉刷新--第三方开源--PullDownListView
下载地址:https://github.com/guojunyi/PullDownListView 使用: xml: <com.pulldownlistview.PullDownListView ...
- iOS开源项目推荐|下拉刷新
MJRefresh - 仅需一行代码就可以为UITableView或者CollectionView加上下拉刷新或者上拉刷新功能.可以自定义上下拉刷新的文字说明. CBStoreHouseRefresh ...
- 【转载】 Android PullToRefresh (ListView GridView 下拉刷新) 使用详解
Android下拉刷新pullToRefreshListViewGridView 转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/3 ...
- Android PullToRefresh (ListView GridView 下拉刷新) 使用详解
转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/38238749,本文出自:[张鸿洋的博客] 群里一哥们今天聊天偶然提到这个git ...
- Android PullToRefresh (ListView GridView 下拉刷新) 使用详解 (转载)
最近项目用到下拉刷新,上来加载更多,这里对PullToRefresh这控件进行了解和使用. 以下内容转载自:http://blog.csdn.net/lmj623565791/article/deta ...
- Android研究之手PullToRefresh(ListView GridView 下拉刷新)使用具体解释
群里一哥们今天聊天偶然提到这个git hub上的控件:pull-to-refresh ,有兴趣的看下,样例中的功能极其强大,支持非常多控件.本篇博客具体给大家介绍下ListView和GridVi ...
- 【转】Android PullToRefresh (ListView GridView 下拉刷新) 使用详解
最近项目用到下拉刷新,上来加载更多,这里对PullToRefresh这控件进行了解和使用. 以下内容转载自:http://blog.csdn.net/lmj623565791/article/deta ...
随机推荐
- 1.4.2 solr字段类型--(1.4.2.5)使用枚举字段
1.4.2 solr字段类型 (1.4.2.1) 字段类型定义和字段类型属性. (1.4.2.2) solr附带的字段类型 (1.4.2.3) 使用货币和汇率 (1.4.2.4) 使用Dates(日期 ...
- a 中调用js的几种方法
我们常用的在a标签中有点击事件:1. a href="javascript:js_method();" 这是我们平台上常用的方法,但是这种方法在传递this等参数的时候很容易出问题 ...
- 不停服务情况下升级nginx
第三方支付平台因安全问题对nginx做了升级操作,为了不影响业务,整个操作过程都不能停服务,因此对升级方法做出了要求.以下为我整理的生产环境实际操作方法,已在第三方支付平台上成功应用,希望对即将或者可 ...
- 重构8-Replace Inheritance with Delegation(委托替换继承)
继承的误用十分普遍.它只能用于逻辑环境,但却经常用于简化,这导致复杂的没有意义的继承层次.看下面的代码: public class Sanitation{ public String WashHand ...
- linux_iptables 详解
iptables工具__过滤包—命令(-A.-I.-D.-R.-L等).参数(-p.-s.-d.--sport.--dport.-i.-o等).动作-j (ACCEPT.DROP.REJECT.RED ...
- hdu 3585 二分+最大团
题目:给出平面上n个点,现在找m个点,并且使得这m个点最近的两个最远. 分析:显然这满足二分的性质,二分答案,根据点距离需要大于等于二分值重新构造新图,则问题变成了:在新图中找出满足所有点对之间的距离 ...
- 洛谷P1251 餐巾(网络流)
P1251 餐巾 15通过 95提交 题目提供者该用户不存在 标签网络流贪心 难度提高+/省选- 提交该题 讨论 题解 记录 最新讨论 为什么我全部10个测试点都对… 题目描述 一个餐厅在相继的N天里 ...
- MVC基础(很基础很基础~~~)
最近工作比较不忙,准备学习一些东西,作为一个菜鸟,不断学习新东西(我不会的东西)充实自己真的很重要,所以整理一下基础的mvc知识,以备不时之需.呵呵~~ 首先感谢原文作者:QLeelulu的文章htt ...
- 默认样式重置 (css reset)
body,p,h1,h2,h3,h4,h5,h6,dl,dd,t{margin:0; font-size:12px;/* font-family:XX; */} ol,ul{list-style:no ...
- HttpContext 讲解
HttpContext类:封装有关个别HTTP请求的所有HTTP特定的信息,又叫上下文.看到这个解释,我觉得有些抽象,Http特定信息具体又是什么?看了下备注:为继承 IHttpModule 和 IH ...