Pulltorefreshgridview with pull-flush, pull-up loaded GridView control

Source: Internet
Author: User

: 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.