The following app basically has the function of Drop-down refresh, used to basically use Xlistview or write a drop-down refresh, the recent Google provides an official Drop-down refresh control swiperefreshlayout, I feel good ah, see accustomed to the traditional Drop-down refresh, This is a refreshing sensation (the seemingly-known app already uses this drop-down refresh).
Google also gave the V4 Compatibility Pack on the official website:
Let's take a look at the code in the layout file (I've got a ListView here. Of course you can put other controls as long as you're happy.)
<android.support.v4.widget.swiperefreshlayout android:
Id= "@+id/main_srl_bloglist" android:layout_width= "Fill_parent" android:layout_height= "Fill_parent" > <listview android:id= "@+id/main_lv_bolg_list" android:layout_width= "Fill_parent" android:layout_height= "Fill_parent" android:divider= "#00000000" android:dividerheight= "5DP" ></ListView> </ Android.support.v4.widget.swiperefreshlayout>
finally take a look at the code in Activiy (here I use the androidannotations so I don't write findviewbyid haha)
//set the color of the animation when refreshed, you can set 4 Mswiperefreshlayout.setcolorschemeresources (Android. R.color.holo_blue_light, android. R.color.holo_red_light, android. R.color.holo_orange_light, android.
R.color.holo_green_light); mswiperefreshlayout.setonrefreshlistener (new Swiperefreshlayout.onrefreshlistener () { @Override public void onrefresh () {
mIndex=1;
Mbloglist.clear (); loadblogdata ()
; } });
It's good to call a method to get the data in Onrefresh. Don't forget to modify the status
Mswiperefreshlayout.setrefreshing (FALSE);
haha before to write tons of code with Swiperefreshlayout on these lines of code is not very convenient.