PullToRefresh源码分析

版权声明:版权声明:本文为博主原创文章,未经博主允许不得转载,违者必究。 https://blog.csdn.net/Cricket_7/article/details/89027546

1,功能介绍

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

 

 

2,导入过程

  • 导入地址

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

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

 

 

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

  • 找到入口

  • 布局文件添加

<com.handmark.pulltorefresh.library.PullToRefreshListView

    android:id="@+id/pull_refresh_list"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    android:cacheColorHint="#00000000"

    android:divider="#19000000"

    android:dividerHeight="4dp"

    android:fadingEdge="none"

    android:fastScrollEnabled="false"

    android:footerDividersEnabled="false"

    android:headerDividersEnabled="false"

    android:smoothScrollbar="true" />
  • 找到控件

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<ListView>() {

   @Override

   public void onRefresh(PullToRefreshBase<ListView> 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<ListView>() {

   @Override

   public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {

      //下拉加载

   }





   @Override

   public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) {

        //上拉刷新



   }

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

mPullRefreshListView.onRefreshComplete();

 

 

 

 

 

 

 

 

猜你喜欢

转载自blog.csdn.net/Cricket_7/article/details/89027546
0条评论
添加一条新回复