程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> 使用PullToRefresh區分下拉刷新和上拉加載

使用PullToRefresh區分下拉刷新和上拉加載

編輯:C++入門知識

使用PullToRefresh區分下拉刷新和上拉加載


關於怎麼使用PullToRefresh,網上已經有很多的文章了,在這裡就不贅述了。

在使用PullToRefresh這個庫的時候需要區分是上拉還是下拉,百度一下就能得到一個修改PullToRefresh.java源文件的方法,如http://blog.csdn.net/losetowin/article/details/18261389該博文中提到的方法。

其實PullToRefresh已經給我們提供了方法,查看源碼。

com.handmark.pulltorefresh.library.PullToRefreshBase.java裡面設置刷新監聽的一段代碼:

	@Override
	public final void setOnRefreshListener(OnRefreshListener listener) {
		mOnRefreshListener = listener;
		mOnRefreshListener2 = null;
	}

	@Override
	public final void setOnRefreshListener(OnRefreshListener2 listener) {
		mOnRefreshListener2 = listener;
		mOnRefreshListener = null;
	}

再看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);

	}
所以在使用的時候可以:

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


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved