Use PullToRefresh to differentiate between pull-down refresh and pull-up loading

Source: Internet
Author: User

Use PullToRefresh to differentiate between pull-down refresh and pull-up loading

There are a lot of articles on how to use PullToRefresh. I will not go into details here.

When using the PullToRefresh library, you need to distinguish between PullToRefresh and pull-down. Baidu will get a method to modify the PullToRefresh. java source file, such as callback.

In fact, PullToRefresh has provided us with a method to view the source code.

Com. handmark. pulltorefresh. library. PullToRefreshBase. java sets a piece of code to refresh the listener:

@Overridepublic final void setOnRefreshListener(OnRefreshListener
 
   listener) {mOnRefreshListener = listener;mOnRefreshListener2 = null;}@Overridepublic final void setOnRefreshListener(OnRefreshListener2
  
    listener) {mOnRefreshListener2 = listener;mOnRefreshListener = null;}
  
 

Let's look at com. handmark. pulltorefresh. library. PullToRefreshBase. OnRefreshListener2.

/** * An advanced version of the Listener to listen for callbacks to Refresh. * This listener is different as it allows you to differentiate between Pull * Ups, and Pull Downs. *  * @author Chris Banes */public static interface OnRefreshListener2
  
    {// TODO These methods need renaming to START/END rather than DOWN/UP/** * onPullDownToRefresh will be called only when the user has Pulled from * the start, and released. */public void onPullDownToRefresh(final PullToRefreshBase
   
     refreshView);/** * onPullUpToRefresh will be called only when the user has Pulled from * the end, and released. */public void onPullUpToRefresh(final PullToRefreshBase
    
      refreshView);}
    
   
  
Therefore, you can:

mPullRefreshListView.setOnRefreshListener(new  com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener2
  
   () {@Overridepublic void onPullDownToRefresh(PullToRefreshBase
   
     refreshView) {Toast.makeText(PullToRefreshListActivity.this, "onPullDownToRefresh", Toast.LENGTH_SHORT).show();new GetDataTask().execute();}@Overridepublic void onPullUpToRefresh(PullToRefreshBase
    
      refreshView) {Toast.makeText(PullToRefreshListActivity.this, "onPullUpToRefresh", Toast.LENGTH_SHORT).show();new GetDataTask().execute();}});
    
   
  


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.