下拉刷新和上拉加载更多的前提是能够判断当前显示的数据在数据源中的位置,第一个数据和最后一个数据是否处于可视状态
<pre style="font-family: 宋体; font-size: 12pt; background-color: rgb(39, 40, 34);"><span style="color: rgb(248, 248, 242);"><span style="color:#a6e22e;"><strong>listView</strong></span><span style="color:#f72671;">.</span>setOnScrollListener(<span style="color:#f72671;"><strong>new </strong></span><span style="color:#66d9ef;"><strong><em>AbsListView.OnScrollListener</em></strong></span>() {
<span style="color:#f72671;"><strong>boolean </strong></span><span style="color:#a6e22e;"><strong>isLastRow </strong></span><span style="color:#f72671;">= </span><span style="color:#f72671;"><strong>false</strong></span>;
<span style="color:#f72671;"><strong>boolean </strong></span><span style="color:#a6e22e;"><strong>isFirstVisible </strong></span><span style="color:#f72671;">= </span><span style="color:#f72671;"><strong>true</strong></span>;
<span style="color:#f72671;"><strong>public void </strong></span>onScrollStateChanged(AbsListView <span style="color:#a6e22e;">view</span>, <span style="color:#f72671;"><strong>int </strong></span><span style="color:#a6e22e;">scrollState</span>) {
<span style="color:#808080;"><em>//正在滚动时回调,回调2-3次,手指没抛则回调2次。scrollState = 2的这次不回调
</em></span><span style="color:#808080;"><em> //回调顺序如下
</em></span><span style="color:#808080;"><em> //第1次:scrollState = SCROLL_STATE_TOUCH_SCROLL(1) 正在滚动
</em></span><span style="color:#808080;"><em> //第2次:scrollState = SCROLL_STATE_FLING(2) 手指做了抛的动作(手指离开屏幕前,用力滑了一下)
</em></span><span style="color:#808080;"><em> //第3次:scrollState = SCROLL_STATE_IDLE(0) 停止滚动
</em></span><span style="color:#808080;"><em> //当屏幕停止滚动时为0;当屏