From 70265eba3eb15c73b0718913fb1d4b7275acb5db Mon Sep 17 00:00:00 2001 From: Boelroy Date: Wed, 5 Mar 2014 10:44:06 +0800 Subject: [PATCH] fix the bug when there is only header in pulltorefreshListView --- .../library/PullToRefreshListView.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/library/src/com/handmark/pulltorefresh/library/PullToRefreshListView.java b/library/src/com/handmark/pulltorefresh/library/PullToRefreshListView.java index 0aa9a27d6..56a0d7cfb 100644 --- a/library/src/com/handmark/pulltorefresh/library/PullToRefreshListView.java +++ b/library/src/com/handmark/pulltorefresh/library/PullToRefreshListView.java @@ -62,6 +62,36 @@ public final Orientation getPullToRefreshScrollDirection() { return Orientation.VERTICAL; } + @Override + protected boolean isFirstItemVisible() { + final Adapter adapter = mRefreshableView.getAdapter(); + + if ((null == adapter || adapter.isEmpty()) && !(getRefreshableView().getHeaderViewsCount() > 1)) { + if (DEBUG) { + Log.d(LOG_TAG, "isFirstItemVisible. Empty View."); + } + return true; + + } else { + + /** + * This check should really just be: + * mRefreshableView.getFirstVisiblePosition() == 0, but PtRListView + * internally use a HeaderView which messes the positions up. For + * now we'll just add one to account for it and rely on the inner + * condition which checks getTop(). + */ + if (mRefreshableView.getFirstVisiblePosition() <= 1) { + final View firstVisibleChild = mRefreshableView.getChildAt(0); + if (firstVisibleChild != null) { + return firstVisibleChild.getTop() >= mRefreshableView.getTop(); + } + } + } + + return false; + } + @Override protected void onRefreshing(final boolean doScroll) { /**