项目作者: JamesKing9

项目描述 :
学习 android-pulltorefresh 库的使用
高级语言: Java
项目地址: git://github.com/JamesKing9/learn-android-pulltorefresh.git
创建时间: 2016-12-07T04:02:54Z
项目社区:https://github.com/JamesKing9/learn-android-pulltorefresh

开源协议:Apache License 2.0

下载


Pull To Refresh for Android

Note This library is deprecated(被 Google废弃了,就是不在维护的意思), a swipe refresh(上拉加载) layout is available in the v4 support library.


This project aims to provide a reusable pull to refresh widget for Android.

Screenshot

Repository at https://github.com/johannilsson/android-pulltorefresh.

Usage(用法)

Layout

  1. <!--
  2. The PullToRefreshListView replaces a standard ListView widget.
  3. (使用 PullToRefreshListView 控件 替换掉 a standard ListView widget 的位置)
  4. -->
  5. <com.markupartist.android.widget.PullToRefreshListView
  6. android:id="@+id/android:list"
  7. android:layout_height="fill_parent"
  8. android:layout_width="fill_parent"
  9. ></com.markupartist.android.widget.PullToRefreshListView>

Activity

  1. // Set a listener(监听器) to be invoked(回调) when the list should be refreshed(需要被刷新的时候).
  2. ((PullToRefreshListView) getListView()).setOnRefreshListener(new OnRefreshListener() {
  3. @Override
  4. public void onRefresh() {
  5. // Do work to refresh the list here.(在这里做 refresh 的业务逻辑)
  6. new GetDataTask().execute();
  7. }
  8. });
  9. // 一个 AsyncTask 的子类
  10. private class GetDataTask extends AsyncTask<Void, Void, String[]> {
  11. ...
  12. @Override
  13. protected void onPostExecute(String[] result) {
  14. mListItems.addFirst("Added after refresh...");
  15. // Call onRefreshComplete when the list has been refreshed.(当 list 被刷新后,调用 onRefreshComplete() 这个回调方法)
  16. ((PullToRefreshListView) getListView()).onRefreshComplete();
  17. // 完成后,将 result 传递给父类 AsyncTask
  18. super.onPostExecute(result);
  19. }
  20. }

Last Updated(最近的更新)

It’s possible to add a last updated time using the method setLastUpdated
and onRefreshComplete. The text provided to these methods will be set below
the Release to refresh text. Note that(注意:) the time representation is not validated
replaces the previous text, which means that it’s possible and recommended to
add a text similar to “Last Update: 15:23”. This might be changed in future
versions.

1.5 Support(支持 1.5 及以上版本)

To use the widget on 1.5 the necessary drawables needs to be copied to that
projects drawable folder. The drawables needed by the widget can be found in
the drawable-hdpi folder in the library project.

Contributors(参与者)

Are you using this widget?

If you are using this widget please feel free to add your app to the
wiki.

License

Copyright (c) 2011 Johan Nilsson

Licensed under the Apache License, Version 2.0