Pulltorefresh is a great set of Drop-down refresh libraries that support:
1.ListView
2.ExpandableListView
3.GridView
4.WebView
A variety of commonly used view types need to be refreshed, and also very convenient to use.
(Download address: Https://github.com/chrisbanes/Android-PullToRefresh)
Download it, import it into Eclipse, and import it into your project as a library.
One, nonsense less say, pull down to refresh go.
1. Add the view you want to use in your layout file, like here I want to use a expandablelistview that supports the dropdown
<com.handmark.pulltorefresh.library.pulltorefreshexpandablelistview
android:id= "@+id/expand_list"
Android:layout_width= "Match_parent"
2. Make simple settings in your activity code:
Mexpandlist = (Pulltorefreshexpandablelistview) Rootview.findviewbyid (r.id.expand_list);
Mexpandlist.getrefreshableview (). Setgroupindicator (null);
Mexpandlist.getrefreshableview (). Setdivider (null);
Mexpandlist.getrefreshableview (). Setselector (Android. r.color.transparent);
Mexpandlist.getrefreshableview (). Setongroupclicklistener (this);
The first line is to find this view, the last line is to add a refreshed listener to it, the middle of a few lines is my expandablelistview to make some settings.
In fact, you can already drop the refresh, but the code to be run when the refresh is written, and why the dropdown will not be collected, and look down.
3. Methods to execute when the Drop-down is refreshed Onrefresh ()
@Override public
void Onrefresh (pulltorefreshbase<expandablelistview> refreshview) {
if (! isrefreshing) {
isrefreshing = true;
Updatelist (true);
else {
mexpandlist.onrefreshcomplete ();
}
}
In general, we will open another thread to get the data, so here will add a judgment, if already in the data, on the Onrefreshcomplete (), is to pull down, or to open a new thread to fetch data, after the recall also to Onrefreshcomplete () Oh!
Two, pull the load
If you do not want to spend more time to write a pull load on their own, you might as well try the Pulltorefresh pull effect Oh!
The Pulltorefresh itself supports drop-and-pull refreshes, so we just need to change the pull-up refresh to the pull-load line.
1. Set mode
Set mode to BOTH
Mexpandlist.setmode (mode.both);
Mexpandlist.getloadinglayoutproxy (False, True). Setpulllabel (GetString (r.string.pull_to_load));
Mexpandlist.getloadinglayoutproxy (False, True). Setrefreshinglabel (GetString (r.string.loading));
When mode is set to Mode.both, the Drop-down and pull up will perform the method in Onrefresh ().
Because the top of the interface, we want to show "pull down refresh", below we want to show "pull load", so the last three lines is to change the bottom part of the text, Getloadinglayoutproxy (False, True) method you can feel.
2. How to distinguish the pull/pull
Online some students are using Onscrolllistener to judge, this is not rigorous, I rely on the header or footer in the visible state to distinguish between pull and pull, if it is down, that header must be visible; Conversely, footer must be visible.
But Pulltorefreshexpandablelistview does not provide such an interface, then we will be small to change the project we introduced, very simple:
Find the Pulltorefreshadapterviewbase.java class under Package "Com.handmark.pulltorefresh.library" and add two new interfaces:
public Boolean Isheadershown () {return
getheaderlayout (). Isshown ();
}
public Boolean Isfootershown () {return
getfooterlayout (). Isshown ();
That'll do. Oh, recompile the project, and your own project.
In Onrefresh () This is done by:
@Override public
void Onrefresh (pulltorefreshbase<expandablelistview> refreshview) {
if (! isrefreshing) {
isrefreshing = true;
if (Mexpandlist.isheadershown ()) {
utils.logd ("Pull-to-refresh");
Refreshonlinestatus (true);
else if (Mexpandlist.isfootershown ()) {
utils.logd ("Pull-to-load-more");
Loadnextpage ();
}
else {
mexpandlist.onrefreshcomplete ();
}
Very simple, so we yd use Pulltorefresh implementation of the Drop-down and pull load, LOL, I hope more or less to help everyone.
Recently found:
1. Realize pull on the monitor, just want to realize OnRefreshListener2 on it, and don't forget SetMode (Mode.both) Oh!
2.PullToRefreshListView there is a bug in the use, in your XML layout, you cannot start to set its visiablity to gone, otherwise, set visiablity in the code for Visiable also has no effect.
Finally put a picture of the effect
The above is a small set to introduce the use of Pulltorefresh to realize the pull down and pull the load, I hope to help everyone, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!