下拉刷新--第三方开源--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 ...
随机推荐
- ios 加载本地html css文件 ps:css和html必须在同一文件夹下面
NSString *path = [[NSBundle mainBundle] bundlePath]; NSURL *baseURL = [NSURL fileURLWithPath:path]; ...
- TFS 2010 使用手册(四)备份与恢复
本文参考了http://developer.51cto.com/art/201010/229066.htm的文章. TFS的备份与恢复一直没有很完整的解决方案,要完成一个很好的备份要有很多的手动步骤才 ...
- LRU算法实现
JDK中的实现 在JDK中LinkedHashMap可以作为LRU算法以及插入顺序的实现,LinkedHashMap继承自HashMap,底层结合hash表和双向链表,元素的插入和查询等操作通过计算h ...
- JavaScript 键盘event.keyCode值列表大全
JavaScript 键盘event.keyCode值列表大全 event.keyCode值列表大全,对于需要根据键盘按键触发相应事件的朋友需要. 网上收集的KeyCode值方便大家查找: k ...
- Float精度 在JS的解决方法
最近在做一个工资核算的系统,所有的运算全部在前台进行,因此用了的是JS来做. 做完以后,经手工核算,发现一个奇怪的问题.就是JS算出来的结果跟用计算器算出来的结果有差距. 想了很久,也没有想出问题出在 ...
- 转:基于TLS1.3的微信安全通信协议mmtls介绍
转自: https://mp.weixin.qq.com/s?__biz=MzAwNDY1ODY2OQ==&mid=2649286266&idx=1&sn=f5d049033e ...
- java实现Composite(组合)模式
组合模式涉及的是一组对象,其中一些对象可能含有其他对象,这些对象也可以含有对象,因此,有些对象代表的是对象群组. Composite模式的设计意图在于:让所有的用户能够用统一的接口处理单个对象以及对象 ...
- C#右键复制路径
using System;//Environment using System.Windows.Forms; //add referece of System.Windows.Forms :DataF ...
- 关于在asp.net的web页面中的全局变量问题
在asp.net的web页面中是不是没有全局变量?有的,在Class类内部的都是,只不过在WebWofm程式中跟WinForm和Console程式有些区别,当页面刷新时,它们的值不会保持,依然会再次初 ...
- Eclipse中tomcat之后,tomcat的相关配置会被Eclipse重置
之前用MyEclipse,在tomcat的conf中修改了配置文件,启动就OK了. 现在改用Eclipse,发现改了,之后发现没有用,Eclipse重启tomcat之后,配置文件就被重置了. 众里寻他 ...