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();}});