学习 android-pulltorefresh 库的使用
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.
Repository at https://github.com/johannilsson/android-pulltorefresh.
<!--
The PullToRefreshListView replaces a standard ListView widget.
(使用 PullToRefreshListView 控件 替换掉 a standard ListView widget 的位置)
-->
<com.markupartist.android.widget.PullToRefreshListView
android:id="@+id/android:list"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
></com.markupartist.android.widget.PullToRefreshListView>
// Set a listener(监听器) to be invoked(回调) when the list should be refreshed(需要被刷新的时候).
((PullToRefreshListView) getListView()).setOnRefreshListener(new OnRefreshListener() {
@Override
public void onRefresh() {
// Do work to refresh the list here.(在这里做 refresh 的业务逻辑)
new GetDataTask().execute();
}
});
// 一个 AsyncTask 的子类
private class GetDataTask extends AsyncTask<Void, Void, String[]> {
...
@Override
protected void onPostExecute(String[] result) {
mListItems.addFirst("Added after refresh...");
// Call onRefreshComplete when the list has been refreshed.(当 list 被刷新后,调用 onRefreshComplete() 这个回调方法)
((PullToRefreshListView) getListView()).onRefreshComplete();
// 完成后,将 result 传递给父类 AsyncTask
super.onPostExecute(result);
}
}
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.
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.
If you are using this widget please feel free to add your app to the
wiki.
Copyright (c) 2011 Johan Nilsson
Licensed under the Apache License, Version 2.0