: Https://github.com/chrisbanes/Android-PullToRefresh
After downloading the extract, import the extras item in the unpacking package
Xml:
<span style= "FONT-SIZE:18PX;" ><com.handmark.pulltorefresh.library.pulltorefreshgridview android:id= "@+id/gvList" android: Layout_width= "Match_parent" android:layout_height= "match_parent" android:horizontalspacing= "5DP " android:verticalspacing= "5DP" android:layout_margin= "5DP" android:numcolumns= "2"/></span>
Note: The height must be set match_parent, otherwise the height is not enough, will not be rendered, then the custom adapter GetView () position will always be 0
Note: You must not set invisible in XML. Otherwise, even if the settings are visible in Java, the Java settings may not be visible where needed.
<span style= "FONT-FAMILY:SIMSUN;FONT-SIZE:18PX;" >private Pulltorefreshgridview gvlist;</span>
private Commodityfiltrategridviewadapter Madapter;
Gvlist = (Pulltorefreshgridview) Findviewbyid (r.id.gvlist); madapter = new Commodityfiltrategridviewadapter (this);
protected void Setgridview () {
Initindicator (); Gvlist.setadapter (Madapter); Gvlist.setmode (mode.both);// Can drop-down refresh and pull-up load Gvlist.setonitemclicklistener (new Onitemclicklistener () {@Overridepublic void Onitemclick (Adapterview <?> parent, View view,int position, long ID) {//Where to do the pulltorefreshgridview after clicking on the item}}); Gvlist.setonrefreshlistener (New onrefreshlistener2<gridview> () {@Override public void Onpulldownto Refresh (pulltorefreshbase<gridview> Refreshview) {//LOG.E ("TAG", "Onpul Ldowntorefresh ");//drop-down refresh pageindex = 1; Getdata_gridview (pageindex);//Get Data asynchronously @Override public void Onpulluptorefre SH (pulltorefreshbase<gridview> Refreshview) {//LOG.E ("TAG", "Onpulluptorefresh" ); Pull-up loading pageindex++; Getdata_gridview (pageindex);//Asynchronous Get Data}}); private void Initindicator () {iloadinglayout startlabels = Gvlist. Getloadinglayoutproxy (True, false); Startlabels.setpulllabel ("drop-down refresh ...");//Just drop-down, show prompt Startlabels.setrefreshinglabel ("refresh ...");//Refresh Startl Abels.setreleaselabel ("Release refresh Data ...");//down to a certain distance, the prompt displayed iloadinglayout endlabels = Gvlist.getloadinglayoutproxy ( False, True); Endlabels.setpulllabel ("Pull load ...");//Just drop-down, the prompt displayed Endlabels.setrefreshinglabel ("Loading ...");//Refresh Endlabels. Setreleaselabel ("Release load Data ...");//down to a certain distance, show the prompt}
protected void Getdata_gridview (final int page) {
Here is the use of asynchronous load data operations
<span style= "font-family:arial, Helvetica, Sans-serif;" >gvlist.onrefreshcomplete (); After </span>//loading is complete, set refresh is complete! </span>
}
Note: When the pull-up does not have new data, execute:gvlist.setmode (Mode.pull_down_to_refresh); indicates that only drop-down refreshes
Note: The list slides to the specified location: Gvlist.getrefreshableview (). SetSelection (count);
Pulltorefreshgridview with pull-flush, pull-up loaded GridView control