1.加入library后直接布局 library下载地址:http://pan.baidu.com/s/1dFJu8pF
<com.handmark.pulltorefresh.library.PullToRefreshListView android:id="@+id/jizhan_listview" android:layout_width="match_parent" android:layout_height="match_parent" android:fadingEdge="none" ptr:ptrHeaderTextColor="#ffffff"> </com.handmark.pulltorefresh.library.PullToRefreshListView>
2. 设备下拉和上划
pullToRefreshListView= (PullToRefreshListView) findViewById(R.id.jizhan_listview);
pullToRefreshListView.setMode(PullToRefreshBase.Mode.BOTH);
3. 添加上划,下拉事件监听 如果动作完成后不执行onrefreshComplete 则默认的加载动画,会一直不停的旋转
pullToRefreshListView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ListView>() { /** * 下拉刷新事件 * */ @Override public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {
/****** 操作完成后:执行 pullToRefreshListView.onRefreshComplete();****/
pullToRefreshListView.onRefreshComplete();
} /** * * 上划加载更多 * */ @Override public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) {
/****** 操作完成后:执行 pullToRefreshListView.onRefreshComplete(); ****/
pullToRefreshListView.onRefreshComplete(); /***/ } });
4. 点击事件
pullToRefreshListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { } });
5.
设置pullToRefreshListView 下拉上划时显示的提示文字。
private void init1() { ILoadingLayout startLabels = pullToRefreshListView .getLoadingLayoutProxy(true, true); startLabels.setPullLabel("下拉刷新...");// 刚下拉时,显示的提示 startLabels.setRefreshingLabel("正在载入...");// 刷新时 startLabels.setReleaseLabel("放开刷新...");// 下来达到一定距离时,显示的提示 ILoadingLayout endLabels = pullToRefreshListView.getLoadingLayoutProxy( true, true); endLabels.setPullLabel("上拉刷新...");// 刚下拉时,显示的提示 endLabels.setRefreshingLabel("正在载入...");// 刷新时 endLabels.setReleaseLabel("放开刷新..."); }
6.设置长按事件
pullToRefreshListView.getRefreshableView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { } });