關於怎麼使用PullToRefresh,網上已經有很多的文章了,在這裡就不贅述了。
在使用PullToRefresh這個庫的時候需要區分是上拉還是下拉,百度一下就能得到一個修改PullToRefresh.java源文件的方法,如http://blog.csdn.net/losetowin/article/details/18261389該博文中提到的方法。
其實PullToRefresh已經給我們提供了方法,查看源碼。
com.handmark.pulltorefresh.library.PullToRefreshBase.java裡面設置刷新監聽的一段代碼:
@Override public final void setOnRefreshListener(OnRefreshListenerlistener) { mOnRefreshListener = listener; mOnRefreshListener2 = null; } @Override public final void setOnRefreshListener(OnRefreshListener2 listener) { mOnRefreshListener2 = listener; mOnRefreshListener = null; }
/** * 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); }
mPullRefreshListView.setOnRefreshListener(new com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener2() { @Override public void onPullDownToRefresh( PullToRefreshBase refreshView) { Toast.makeText(PullToRefreshListActivity.this, "onPullDownToRefresh", Toast.LENGTH_SHORT).show(); new GetDataTask().execute(); } @Override public void onPullUpToRefresh( PullToRefreshBase refreshView) { Toast.makeText(PullToRefreshListActivity.this, "onPullUpToRefresh", Toast.LENGTH_SHORT).show(); new GetDataTask().execute(); } });