PullToRefresh源码分析

1,功能介绍

  • 上拉刷新,下拉加载思想

PullToRefresh源码分析_第1张图片

 

 

2,导入过程

  • 导入地址

https://github.com/chrisbanes/Android-PullToRefresh

PullToRefresh源码分析_第2张图片

  • 创建一个新的工程,导入Moudel

 

PullToRefresh源码分析_第3张图片

PullToRefresh源码分析_第4张图片

PullToRefresh源码分析_第5张图片

 

3,我需要的Listview上拉刷新和下拉加载

  • 找到入口

PullToRefresh源码分析_第6张图片

  • 布局文件添加

  • 找到控件

mPullRefreshListView = (PullToRefreshListView) findViewById(R.id.pull_refresh_list);

PullToRefreshListActivity 里面找到下拉刷新的代码

  •  
// Set a listener to be invoked when the list should be refreshed.

mPullRefreshListView.setOnRefreshListener(new OnRefreshListener() {

   @Override

   public void onRefresh(PullToRefreshBase refreshView) {

      String label = DateUtils.formatDateTime(getApplicationContext(), System.currentTimeMillis(),

            DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL);





      // Update the LastUpdatedLabel

      refreshView.getLoadingLayoutProxy().setLastUpdatedLabel(label);





      // Do work to refresh the list here.

      new GetDataTask().execute();

   }

});
  • 调用可以看到我们正在需要的上拉刷新,下拉加载

mPullRefreshListView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2() {

   @Override

   public void onPullDownToRefresh(PullToRefreshBase refreshView) {

      //下拉加载

   }





   @Override

   public void onPullUpToRefresh(PullToRefreshBase refreshView) {

        //上拉刷新



   }

});
  •  刷新或者加载结束后需要调用方法

mPullRefreshListView.onRefreshComplete();

 

 

 

 

 

 

 

 

你可能感兴趣的:(PullToRefresh源码分析)