@@ -55,7 +55,7 @@ private static FrameLayout.LayoutParams convertEmptyViewLayoutParams(ViewGroup.L
55
55
return newLp ;
56
56
}
57
57
58
- private int mSavedLastVisibleIndex = - 1 ;
58
+ private boolean mLastItemVisible ;
59
59
private OnScrollListener mOnScrollListener ;
60
60
private OnLastItemVisibleListener mOnLastItemVisibleListener ;
61
61
private View mEmptyView ;
@@ -110,23 +110,12 @@ public final void onScroll(final AbsListView view, final int firstVisibleItem, f
110
110
+ ". Total Items:" + totalItemCount );
111
111
}
112
112
113
- // If we have a OnItemVisibleListener, do check...
113
+ /**
114
+ * Set whether the Last Item is Visible. lastVisibleItemIndex is a
115
+ * zero-based index, so we minus one totalItemCount to check
116
+ */
114
117
if (null != mOnLastItemVisibleListener ) {
115
-
116
- // Detect whether the last visible item has changed
117
- final int lastVisibleItemIndex = firstVisibleItem + visibleItemCount ;
118
-
119
- /**
120
- * Check that the last item has changed, we have any items, and that
121
- * the last item is visible. lastVisibleItemIndex is a zero-based
122
- * index, so we add one to it to check against totalItemCount.
123
- */
124
- if (visibleItemCount > 0 && (lastVisibleItemIndex + 1 ) == totalItemCount ) {
125
- if (lastVisibleItemIndex != mSavedLastVisibleIndex ) {
126
- mSavedLastVisibleIndex = lastVisibleItemIndex ;
127
- mOnLastItemVisibleListener .onLastItemVisible ();
128
- }
129
- }
118
+ mLastItemVisible = (totalItemCount > 0 ) && (firstVisibleItem + visibleItemCount >= totalItemCount - 1 );
130
119
}
131
120
132
121
// If we're showing the indicator, check positions...
@@ -140,9 +129,17 @@ public final void onScroll(final AbsListView view, final int firstVisibleItem, f
140
129
}
141
130
}
142
131
143
- public final void onScrollStateChanged (final AbsListView view , final int scrollState ) {
132
+ public final void onScrollStateChanged (final AbsListView view , final int state ) {
133
+ /**
134
+ * Check that the scrolling has stopped, and that the last item is
135
+ * visible.
136
+ */
137
+ if (state == OnScrollListener .SCROLL_STATE_IDLE && null != mOnLastItemVisibleListener && mLastItemVisible ) {
138
+ mOnLastItemVisibleListener .onLastItemVisible ();
139
+ }
140
+
144
141
if (null != mOnScrollListener ) {
145
- mOnScrollListener .onScrollStateChanged (view , scrollState );
142
+ mOnScrollListener .onScrollStateChanged (view , state );
146
143
}
147
144
}
148
145
0 commit comments