From 4ec52b491ec01b2856e45291f733fd63e6bfbc57 Mon Sep 17 00:00:00 2001 From: chaohui Date: Tue, 26 Jul 2016 15:27:10 +0800 Subject: [PATCH] fix bug. --- .../PullToRefreshUseActivity.java | 11 +++++++---- .../chad/library/adapter/base/BaseQuickAdapter.java | 6 ++++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/chad/baserecyclerviewadapterhelper/PullToRefreshUseActivity.java b/app/src/main/java/com/chad/baserecyclerviewadapterhelper/PullToRefreshUseActivity.java index b657aabf2..2992e6df4 100644 --- a/app/src/main/java/com/chad/baserecyclerviewadapterhelper/PullToRefreshUseActivity.java +++ b/app/src/main/java/com/chad/baserecyclerviewadapterhelper/PullToRefreshUseActivity.java @@ -24,6 +24,8 @@ public class PullToRefreshUseActivity extends Activity implements BaseQuickAdapt private QuickAdapter mQuickAdapter; private SwipeRefreshLayout mSwipeRefreshLayout; + private View notLoadingView; + private static final int TOTAL_COUNTER = 18; private static final int PAGE_SIZE = 6; @@ -67,8 +69,10 @@ public void onLoadMoreRequested() { public void run() { if (mCurrentCounter >= TOTAL_COUNTER) { mQuickAdapter.notifyDataChangedAfterLoadMore(false); - View view = getLayoutInflater().inflate(R.layout.not_loading, (ViewGroup) mRecyclerView.getParent(), false); - mQuickAdapter.addFooterView(view); + if (notLoadingView == null) { + notLoadingView = getLayoutInflater().inflate(R.layout.not_loading, (ViewGroup) mRecyclerView.getParent(), false); + } + mQuickAdapter.addFooterView(notLoadingView); } else { new Handler().postDelayed(new Runnable() { @Override @@ -80,11 +84,9 @@ public void run() { } } - }); } - @Override public void onRefresh() { new Handler().postDelayed(new Runnable() { @@ -92,6 +94,7 @@ public void onRefresh() { public void run() { mQuickAdapter.setNewData(DataServer.getSampleData(PAGE_SIZE)); mQuickAdapter.openLoadMore(PAGE_SIZE, true); + mQuickAdapter.removeAllFooterView(); mCurrentCounter = PAGE_SIZE; mSwipeRefreshLayout.setRefreshing(false); } diff --git a/library/src/main/java/com/chad/library/adapter/base/BaseQuickAdapter.java b/library/src/main/java/com/chad/library/adapter/base/BaseQuickAdapter.java index 53c928e72..30fb71405 100755 --- a/library/src/main/java/com/chad/library/adapter/base/BaseQuickAdapter.java +++ b/library/src/main/java/com/chad/library/adapter/base/BaseQuickAdapter.java @@ -336,7 +336,7 @@ public void setNewData(List data) { this.mData = data; if (mRequestLoadMoreListener != null) { mNextLoadEnable = true; - mFooterLayout = null; + // mFooterLayout = null; } mLastPosition = -1; notifyDataSetChanged(); @@ -520,6 +520,8 @@ else if ((!mFootAndEmptyEnable || !mHeadAndEmptyEnable) && position == 1 && mFoo return LOADING_VIEW; else return FOOTER_VIEW; + } else if (position > mData.size() + getHeaderLayoutCount()) { + return FOOTER_VIEW; } return getDefItemViewType(position - getHeaderLayoutCount()); } @@ -775,7 +777,7 @@ public void removeFooterView(View footer) { * remove all header view from mHeaderLayout and set null to mHeaderLayout */ public void removeAllHeaderView() { - if (mFooterLayout == null) return; + if (mHeaderLayout == null) return; mHeaderLayout.removeAllViews(); mHeaderLayout = null;