@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { if (mSwipeRefreshLayout.isRefreshing()) { mSwipeRefreshLayout.setRefreshing(false); } mAdapter.swapCursor(data); }
@Override public void onScrollStateChanged(AbsListView view, int scrollState) { super.onScrollStateChanged(view, scrollState); boolean canLoading = SCROLL_STATE_IDLE == scrollState // 停住了,不滑动了 && mListView.getLastVisiblePosition() == mAdapter.getCount() - 1 // 到底了 && (mSearchView == null || !mSearchView.isSearching()) // 用户没有打开搜索框 && !mSwipeRefreshLayout.isRefreshing(); // 当前没有处在刷新状态 // && mAdapter.getCount() > 0; // 不是一开始 if (canLoading) { // 可以加载更多,但是我们需要判断一下是否加载完了,没有更多了 if (mAdapter.getCount() >= mTotal) { Log.d(TAG, "load all done..."); super.loadAllDone(); } else { Log.d(TAG, "load..."); loadMore(mAdapter.getItemId(mAdapter.getCount() - 1)); } } else { Log.d(TAG, "cannot load more!"); } }
@Override public void onLoaderReset(Loader<Cursor> loader) { mAdapter.swapCursor(null); }
private void loadFromLocal() { Bundle args = new Bundle(); args.putInt(TAG, mAdapter.getCount() + getFetchSize()); getLoaderManager().restartLoader(0, args, this); mSwipeRefreshLayout.setRefreshing(true); }